OSGI com.sun.image import using gradle - gradle

Im my project i use the following dependencies to build a captcha in gradle module and deploy it to liferay 7
dependencies{
compile group: 'com.octo.captcha', name: 'jcaptcha', version: tcVersion('com.octo.captcha')
// compile group: 'com.octo.captcha', name: 'jcaptcha-api', version: '2.0-alpha-1'
compile group: 'com.jhlabs', name: 'filters', version: '2.0.235-1'
}
the problem is when i try to deploy my bundle i get the following error
org.osgi.framework.BundleException: Could not resolve module: com.myproject.vaadin.util [810]
Unresolved requirement: Import-Package: com.sun.image.codec.jpeg
apparently, com.sun.image.codec.jpeg is being used. it is in rt.jar in the jdk so i dont need to extra include it, but it seems that i should include it. in gradle the project compiles successfuly and the bundle gets deployed in the gogo shell but when i try to start the bundle i get the descriped error

You dependency is not available in your runtime for your module. When building in Gradle it is available, as mentioned, because it is on your build classpath. In runtime however, you module declares that it needs to import this package from a OSGi bundle, which does not exist.
You have some options to explore here. You can use compileInclude to include the library in a fat Jar in Gradle (Liferay workspace); use the bnd file to include as a resource and set the bundle's classpath to include the jar; build a uber module that carries the package you need to the runtime in its on bundle; or find a bundle that exports it without you needing to build extra stuff.
Bottom line: you need to make the package available in runtime as an exported package.

You will need to configure boot delegation for the OSGi framework to include the com.sun.image.codec.jpeg package.

Related

spring boot plugin and gradle dependency implementation

We have been using gradle spring boot plugin version 1.5.14 and gradle 4.10.3 for our builds. After an upgrade of gradle to 6.2.2, we've also changed dependency-definition from compile group to implementation group i.e.:
compile group: 'org.springframework.boot', name: 'spring-boot-starter-integration'
to
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-integration'.
The fat jar created via gradle assemble does to my surprise not contain the required libs under BOOT-INF/lib anymore? If I replace "implementation" with "compile" it works again as expected.
Is there something which needs to be configured so that spring-boot-plugin adds them? Or do I need to upgrade the project to spring boot 2 beforehand?
Implementation will bring in the dependency only for that module it is declared in.
Compile will allow a module that depends on the module to use the dependency as well.
Say you have Module A depending on Module B.
Module A and B both need the dependency:
com.font:font1:1.1.1
If B uses:
implementation 'com.font:font1:1.1.1'
A will not see font1, and will need to bring it into its own build.gradle file as well.
compile 'com.font:font1:1.1.1'
will make it available to the entire classpath (which should be avoided anyway, and the new equivalent is for libraries which uses 'api' instead of 'compile').
Without seeing your project directory, I'm assuming that some dependency is not being pulled into a place where it used to be grabbed from a lower dependency in the hierarchy. You should be able to find the missing dependencies easily by changing compile to implementation one at a time, unless you have a huge multi-module project.

when downloading a dependency jar, how to make its dependencies get downloaded

I have built two jars and put them in Artifactory. One of the jars depends on the other (the dependency is in its build.gradle file). When I download the main jar as a dependency of my main app, the dependent jar is not downloaded. The only way I can get both is to put two compile statements in the build.gradle. How do I cause the dependent jar to also get downloaded?
The main jar file is user-cache.jar and it depends on blue-redis.jar. The build.gradle in the app that uses my main jar uses this compile statement:
compile(group: 'etd.user-cache', name: 'user-cache', version: '1.0.2', ext: '12.SNAPSHOT.jar')
The build.gradle for user-cache has this in it:
compile(group: 'etd.blue-redis', name: 'blue-redis', version: '1.0.1', ext: '4.SNAPSHOT.jar')
When I build my app, it only gets user-cache.jar. That makes it necessary to put both compile statements in my app's build.jar
What should I do to cause the blue-redis.jar to also be downloaded without needing its compile statement?
I assume that you are using a maven repository in Artifactory. When gradle is doing dependency resolution it will attempt to download a POM file and check for transitive dependencies as well as parent poms which may list additional dependencies.
To get the desired behavior, when you publish the main jar to Artifactory you need to include in its POM file a dependency on the other JAR.

Gradle transient dependencies

I have a project "lib" with declares dependency on third party library (lets say, redis).
dependencies{
implementation group: 'redis.clients', name: 'jedis', version: '2.9.0'
}
I have another project, "application", which is declares dependency on "lib" project in very similar way.
The problem: unless I adding redis dependency to the "application" project as well, it fails at runtime due to missing redis dependency (despite that it itself doesn't make any direct use of redis).
I want to declare "redis" dependency inside "lib" project in such way, so "lib" will be already "bundled" with "redis" inside, so everyone using "lib" will have to declare only "lib" dependency.
How to do that?
Assuming you apply the java or java-library plugins, you should not have to do anything.
A dependency added to the implementation scope in Gradle is visible to consumers of that project for their runtime classpath. It is however not visible to the compile classpath.
In order to understand better what's happening, you can check the different classpath by running ./gradlew <project>:dependencies --configuration runtimeClasspath on both projects and see what is the output, of course replacing <project> with the project name or leaving empty for the root project.

Including class files in gradle build script

I have useful java class files from a old project on my computer and would like to include them in a build.gradle script for a new project. I also am using a library off the Maven repository and a jar file on my computer. I'm only have problem with including the classes and no problem with either of the others. Here is the dependency block.
dependencies {
compile 'no.tornado:tornadofx:1.7.14' //works
compile files('../lib/opencv-320.jar') //works
compile files('../oldProject/com') } //seems ok in IntelliJ, but won't compile
By including the oldProject/com in this way IntelliJ is able to see the dependency and recognize the class. However, when proceeding to run the app, here is the error that suggests the package "util" and class "MultiArray" in oldProject/com are not being seen by the Kotlin compiler.
Information: Kotlin: kotlinc -jvm 1.2.21 (JRE 1.80_71-b15)
Error:(3,8) Kotlin: Unresolved reference util
Error:(18,17) Kotlin: Unresolved reference MultiArray
Here is the include line in the top level settings.gradle file
include ('../oldProject/com')
com is your top-level package and not the directory root. You have to add the dependency
compile files('../oldProject')
IntelliJ can detect directory prefixes, but Gradle does not do that.

Gradle does not download complete dependencies

Im trying to download and build spring-data-hadoop 2.4.0.RELEASE using the following decleration in my dependencies.gradle:
dependencies {
...
// compile('org.springframework.data:spring-data_hadoop:2.4.0.RELEASE')
compile group: 'org.springframework.data', name: 'spring-data-hadoop', version: '2.4.0.RELEASE'
...
}
Refreshing gradle now results in downloading the newly added dependency BUT the data is not consistend. I got the following external dependencies after the download:
I thought everything is fine now... but I am wrong. Lets open up one of those and look depper into the packages:
If you compare the content of org.springframework.data.hadoop.config with the official API you will notice, that in this package, there should be much more content. The annotations package for example.
How can it be that gradle is not downloading the complete source?
There is a separate spring-data-hadoop-config with the description "Spring for Apache Hadoop Annotation Configuration", so that's probably where annotations would be.
You are pulling the main jar that should pull the transitive artifacts as well.
the org.springframework.data.hadoop.config.annotation is included inside
compile group: 'org.springframework.data', name: 'spring-data-hadoop-config', version: '2.4.0.RELEASE'

Resources