Grails exclude a jar from dependency - spring

I have a grails 2.4.5 project with dependency section in BuildConfig.groovy as:
dependencies {
// specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes eg.
//compile ":memcached:1.0.3.2"
//compile ":grails-melody:1.47.2"
// runtime 'mysql:mysql-connector-java:5.1.16'
compile "org.grails:grails-core:2.2.2.BUILD-SNAPSHOT", { exclude "grails"} // added for 2.2.1 support of inner class enums (http://jira.grails.org/browse/GRAILS-9627)
}
The program on running gives this error:
Fatal error during compilation org.springframework.beans.factory.BeanDefinitionStoreException: Failed to read candidate component class: URL [jar:file:/C:/Users/Rahulserver/.m2/repository/org/grails/grails-project-api/2.4.5/grails-project-api-2.4.5.jar!/org/codehaus/groovy/grails/compiler/Grailsc.class]; nested exception is java.lang.IncompatibleClassChangeError: class org.springframework.core.type.classreading.ClassMetadataReadingVisitor has interface org.springframework.asm.ClassVisitor as super class
I did some research on error java.lang.IncompatibleClassChangeError: class org.springframework.core.type.classreading.ClassMetadataReadingVisitor has interface org.springframework.asm.ClassVisitor as super class
And found here that with spring 3.2 above, we don't need any spring-asm explicitly.
The dependency report on my project shows that org.grails:grails-core:2.2.2.BUILD-SNAPSHOT depends on spring-asm:
+--- org.grails:grails-core:2.2.2.BUILD-20130226.093746-1
| \--- commons-collections:commons-collections:3.2.1
| \--- commons-io:commons-io:2.1
| \--- org.springframework:spring-context:4.0.9.RELEASE
| \--- org.springframework:spring-beans:4.0.9.RELEASE
| \--- org.springframework:spring-aspects:3.1.4.RELEASE
| \--- org.springframework:spring-expression:4.0.9.RELEASE
| \--- org.springframework:spring-asm:3.1.4.RELEASE
| \--- org.springframework:spring-context-support:4.0.9.RELEASE
| \--- org.springframework:spring-core:4.0.9.RELEASE
| \--- org.springframework:spring-web:4.0.9.RELEASE
| \--- aopalliance:aopalliance:1.0
| \--- org.hibernate.javax.persistence:hibernate-jpa-2.0-api:1.0.1.Final
| \--- commons-validator:commons-validator:1.3.1
| \--- org.springframework:spring-aop:4.0.9.RELEASE
So what should I do to resolve this conflict? Is there any way I could avoid the
org.springframework:spring-asm:3.1.4.RELEASE dependency?

What is a dependency on Grails 2.2.x doing in a 2.4.5 project?
The bug you are referring to in the comments was fixed in 2.3-M1, so is not present in 2.4.x.
I suspect your errors will disappear if you remove the explicit dependency on grails-core 2.2.2*.

Related

How to resolve JAXB classpath issues on Java 12

Im porting application using JAXB to JDK 11/12 but am completely lost when trying to fix those JAXB classpath issues. I have googled and read basically everything related to this so Im aware of the changes made in Java11, i.e. removal of JAXB from JDK ... However in that case I would assume a trivial fix consisting of adding api and impl JARs on classpath. But this is not working and despite I have those JARs on classpath Im still getting the known exception, despite using 2.3.2 JAXB:
javax.xml.bind.JAXBException
- with linked exception:
[java.lang.ClassNotFoundException: com.sun.xml.internal.bind.v2.ContextFactory]
even if I see the class is in different package and I instruct to use correct package via system variable it does not work either:
gradle -Djavax.xml.bind.context.factory=com.sun.xml.bind.v2.ContextFactory build
javax.xml.bind.JAXBException
- with linked exception:
[java.lang.ClassNotFoundException: com.sun.xml.bind.v2.ContextFactory]
Does anyone have clue how to resolve this? I dont want to play with manifest files etc. It should be possible to just place the right JARs on classpath and that is it, or not?
Summary here but unable to get it working:
http://www.descher.at/descher-vu/2019/01/java-11-jaxb-and-osgi/
Update, dependencies used in Gradle:
- jaxb-xjc has jaxb-runtime (impl.) as transitive dependency. I see it is picked by Gradle but still the same error.
classpath "com.sun.activation:javax.activation:1.2.0"
classpath "jakarta.xml.bind:jakarta.xml.bind-api:2.3.2"
classpath "org.glassfish.jaxb:jaxb-xjc:2.3.2"
classpath"org.glassfish.jaxb:jaxb-core:2.3.0.1"
[org.gradle.internal.operations.DefaultBuildOperationExecutor] Build operation 'Resolve jaxb-runtime.jar (org.glassfish.jaxb:jaxb-runtime:2.3.2)' completed
[org.gradle.internal.component.model.ComponentAttributeMatcher] Selected match org.glassfish.jaxb:jaxb-runtime:2.3.2 configuration runtime from candidates [org.glassfish.jaxb:jaxb-runtime:2.3.2 configuration runtime] for {org.gradle.dependency.bundling=external, org.gradle.jvm.version=12, org.gradle.usage=java-runtime}
This is output of "gradle dependencies" and all the JAXB jars are there, still classpath error is being thrown. The JAR file jaxb-runtime from Glassfish for sure has this ContextFactory class.
runtimeClasspath - Runtime classpath of source set 'main'.
+--- org.springframework.boot:spring-boot-starter-log4j2 -> 2.1.0.RELEASE
| +--- org.apache.logging.log4j:log4j-slf4j-impl:2.11.1
| | +--- org.slf4j:slf4j-api:1.7.25
| | +--- org.apache.logging.log4j:log4j-api:2.11.1
| | \--- org.apache.logging.log4j:log4j-core:2.11.1
| | \--- org.apache.logging.log4j:log4j-api:2.11.1
| +--- org.apache.logging.log4j:log4j-core:2.11.1 (*)
| +--- org.apache.logging.log4j:log4j-jul:2.11.1
| | \--- org.apache.logging.log4j:log4j-api:2.11.1
| \--- org.slf4j:jul-to-slf4j:1.7.25
| \--- org.slf4j:slf4j-api:1.7.25
+--- org.projectlombok:lombok -> 1.18.2
+--- org.apache.commons:commons-lang3 -> 3.8.1
+--- org.apache.commons:commons-collections4 -> 4.4
+--- com.google.guava:guava -> 23.0
| +--- com.google.code.findbugs:jsr305:1.3.9
| +--- com.google.errorprone:error_prone_annotations:2.0.18
| +--- com.google.j2objc:j2objc-annotations:1.1
| \--- org.codehaus.mojo:animal-sniffer-annotations:1.14
+--- org.apache.ws.xmlschema:xmlschema-core -> 2.0.1
+--- org.glassfish.jaxb:jaxb-runtime:2.3.2
| +--- jakarta.xml.bind:jakarta.xml.bind-api:2.3.2
| | \--- jakarta.activation:jakarta.activation-api:1.2.1
| +--- org.glassfish.jaxb:txw2:2.3.2
| +--- com.sun.istack:istack-commons-runtime:3.0.8
| | \--- jakarta.activation:jakarta.activation-api:1.2.1
| +--- org.jvnet.staxex:stax-ex:1.8.1
| | +--- jakarta.activation:jakarta.activation-api:1.2.1
| | \--- jakarta.xml.bind:jakarta.xml.bind-api:2.3.2 (*)
| +--- com.sun.xml.fastinfoset:FastInfoset:1.2.16
| \--- jakarta.activation:jakarta.activation-api:1.2.1
\--- org.glassfish.jaxb:jaxb-core:2.3.0.1
+--- javax.xml.bind:jaxb-api:2.3.0 -> 2.3.1
| \--- javax.activation:javax.activation-api:1.2.0
+--- org.glassfish.jaxb:txw2:2.3.0.1 -> 2.3.2
\--- com.sun.istack:istack-commons-runtime:3.0.5 -> 3.0.8 (*)
From some reason I had no luck with Glassfish JARs, but those original Sun/Oracle dependencies worked.

Gradle dependency conflict when using `implementation`

I have a project with two gradle modules: lib and app. I just changed lib's build.gradle to stop exposing a dependency (i.e. I moved from api -> implementation). The app module doesn't directly depend on OkHttp logging interceptor so I figure it's better to not expose it.
lib module's build.gradle:
dependencies {
// api 'com.squareup.okhttp3:logging-interceptor:3.10.0'
implementation 'com.squareup.okhttp3:logging-interceptor:3.10.0'
...
}
app module's build.gradle:
dependencies {
implementation project(':lib')
implementation group: 'com.zendesk', name: 'support-providers', version: '2.0.0'
...
}
However I'm now seeing a compile problem:
Conflict with dependency 'com.squareup.okhttp3:logging-interceptor' in
project ':app'. Resolved versions for runtime classpath (3.10.0) and
compile classpath (3.8.1) differ
If I look at project structure I see this:
+--- project :lib
...
+--- com.zendesk:support-providers:2.0.0
| +--- com.zendesk:core:1.0.0
| | +--- com.zendesk:java-common:1.13
| | +--- com.google.dagger:dagger:2.12 -> 2.15 (*)
| | +--- com.squareup.retrofit2:retrofit:2.3.0
| | | \--- com.squareup.okhttp3:okhttp:3.8.0 -> 3.8.1
| | | \--- com.squareup.okio:okio:1.13.0
| | +--- com.squareup.retrofit2:converter-gson:2.3.0
| | | +--- com.squareup.retrofit2:retrofit:2.3.0 (*)
| | | \--- com.google.code.gson:gson:2.7
| | +--- com.squareup.okhttp3:logging-interceptor:3.8.1 // <----- SEE HERE
| | | \--- com.squareup.okhttp3:okhttp:3.8.1 (*)
| | +--- com.squareup.okhttp3:okhttp:3.8.1 (*)
| | +--- com.android.support:support-annotations:27.0.2 -
lib isn't revealing any of it's dependencies (obviously) and app depends on Zendesk sdk which depends on different version of OkHttp logging interceptor.
I only see two ways to fix this:
revert api -> implementation in lib module, thus exposing logging interceptor to app module
declare a top level dependency on logging interceptor and set to 3.10 to force Zendesk to use latest:
app build.gradle:
dependencies {
implementation project(':lib')
implementation group: 'com.zendesk', name: 'support-providers', version: '2.0.0'
// used just to force zendesk to use 3.10
implementation 'com.squareup.okhttp3:logging-interceptor:3.10.0'
...
}
Neither of these seem very clean. IMO the app module shouldn't know anything about OkHttp logging interceptor. Is there another option?
If Zendesk updated their library to use implementation for their OkHttp dependency would this solve the problem? Will Gradle let two dependencies use different versions of the same transitive dependency as long as they don't expose to the project as a whole?
with Gradle this works a little different ...
one can either enforce the version 3.10.0:
dependencies {
implementation group: 'com.zendesk', name: 'support-providers', version: '2.0.0'
}
configurations.all() {
resolutionStrategy.force "com.squareup.okhttp3:logging-interceptor:3.10.0"
}
or just exclude version 3.8.1 (which is leaving nothing but the desired version 3.10.0):
dependencies {
implementation ('com.zendesk:support-providers:2.0.0") {
exclude "com.squareup.okhttp3:logging-interceptor:3.8.1"
}
}

What is the default groupId for a maven artifact described as ":artifactId:version"?

I just tried adding a grails plugin as:
compile "org.grails.plugins:spring-websocket:1.3.1"
which failed but the following succeeded:
compile ":spring-websocket:1.3.1"
why did this happen?
The two are identical (or should be) as far as I am aware. Indeed I can add the following to my BuildConfig.groovy:
compile "org.grails.plugins:spring-websocket:1.3.1"
And I see the following in my dependency report:
+--- org.grails.plugins:spring-websocket:1.3.1
| \--- org.springframework:spring-messaging:4.1.5.RELEASE
| \--- org.springframework:spring-websocket:4.1.5.RELEASE
| \--- com.fasterxml.jackson.core:jackson-databind:2.4.3
| \--- com.fasterxml.jackson.core:jackson-annotations:2.4.0
| \--- com.fasterxml.jackson.core:jackson-core:2.4.3
The grails documentation 'Plugin Dependencies' says:
If you don't specify a group id the default plugin group id of org.grails.plugins is used.
I do not know why it did not work for you, but it should. I have checked all of this on Grails 2.5.4 but earlier versions of Grails 2 I believe operate in the same manner.

Grails 2.2 to 2.3 - jersey jaxrs plugin dependencies could not be resolved

I'm migrating my project from grails 2.2 to 2.3 and everything work fine except jaxrs plugin
My BuildConfig.groovy looks like:
...
grails.project.dependency.resolver = "maven"
grails.project.dependency.resolution = {
plugins {
compile ':jaxrs:0.8'
}
}
I got this error message:
| Error Resolve error obtaining dependencies: The following artifacts could not be resolved: org.restlet.gae:org.restlet.ext.json:jar:2.0.0, org.restlet.gae:org.restlet:jar:2.0.0, org.restlet.gae:org.restlet.ext.servlet:jar:2.0.0: Could not find artifact org.restlet.gae:org.restlet.ext.json:jar:2.0.0 in grailsCentral (http://repo.grails.org/grails/plugins) (Use --stacktrace to see the full trace)
| Error Resolve error obtaining dependencies: The following artifacts could not be resolved: org.restlet.gae:org.restlet.ext.json:jar:2.0.0, org.restlet.gae:org.restlet:jar:2.0.0, org.restlet.gae:org.restlet.ext.servlet:jar:2.0.0: Could not find artifact org.restlet.gae:org.restlet.ext.json:jar:2.0.0 in grailsCentral (http://repo.grails.org/grails/plugins) (Use --stacktrace to see the full trace)
| Error Resolve error obtaining dependencies: The following artifacts could not be resolved: org.restlet.gae:org.restlet.ext.json:jar:2.0.0, org.restlet.gae:org.restlet:jar:2.0.0, org.restlet.gae:org.restlet.ext.servlet:jar:2.0.0: Could not find artifact org.restlet.gae:org.restlet.ext.json:jar:2.0.0 in grailsCentral (http://repo.grails.org/grails/plugins) (Use --stacktrace to see the full trace)
| Error The following artifacts could not be resolved: org.restlet.gae:org.restlet.ext.json:jar:2.0.0, org.restlet.gae:org.restlet:jar:2.0.0, org.restlet.gae:org.restlet.ext.servlet:jar:2.0.0: Could not find artifact org.restlet.gae:org.restlet.ext.json:jar:2.0.0 in grailsCentral (http://repo.grails.org/grails/plugins)
| Run 'grails dependency-report' for further information.
When I run the report, I got:
+--- org.grails.plugins:jaxrs:0.8
| >>>> org.restlet.gae:org.restlet.ext.json:2.0.0
| >>>> org.restlet.gae:org.restlet:2.0.0
| \--- com.sun.jersey:jersey-core:1.14
| \--- javax.ws.rs:jsr311-api:1.1.1
| \--- com.sun.jersey:jersey-json:1.14
| >>>> org.restlet.gae:org.restlet.ext.servlet:2.0.0
| \--- com.sun.jersey.contribs:jersey-spring:1.14
| \--- org.springframework:spring-core:3.0.0.RC3
| \--- org.springframework:spring-asm:3.0.0.RC3
| \--- commons-logging:commons-logging:1.1.1
| \--- org.springframework:spring-beans:3.0.0.RC3
| \--- org.springframework:spring-context:3.0.0.RC3
| \--- org.springframework:spring-web:3.0.0.RC3
| \--- org.springframework:spring-aop:3.0.0.RC3
| \--- com.sun.jersey:jersey-server:1.14
| \--- com.sun.jersey:jersey-servlet:1.14
| \--- asm:asm:3.3
| \--- org.spockframework:spock-grails-support:0.7-groovy-2.0
| \--- org.grails.plugins:spock:0.7
How can I fix this ?
I found this post. There's a beta version being develop.
I've done what is suggested:
I added the mavenRepo
mavenRepo 'https://noams.artifactoryonline.com/noams/grails-jaxrs-plugin-snapshots'
And as I use the new Aether (Maven) resolver I configure the jaxrs plugin like this:
compile (':jaxrs:0.10-SNAPSHOT') {
excludes 'spring-core', 'spring-beans', 'spring-context', 'spring-web', 'spring-aop'
}
But org.restlet.ext.json:jar:2.1.4 was still missing so I also have to add this mavenRepo:
mavenRepo 'http://maven.restlet.org'
Application cleaned! Tests Passed!

Finding unwanted code dependencies on transitive dependencies

I want to find all my Java code dependencies on libraries that I have not included as top level dependencies in Gradle.
My first though as to how to accomplish this is to turn off all transitive dependencies in Gradle and see what compilation errors I get.
From my research the way to do this seems to be:
configurations.all { transitive = false }
Is there a better way, or does this do it?
I'm not sure I understand the question, but the command line "gradle dependencies" might help.
For example, consider this (from this modest project):
dependencies {
groovy 'org.codehaus.groovy:groovy-all:1.6.4'
groovy 'com.google.guava:guava-collections:r03'
releaseJars 'org.codehaus.groovy:groovy-all:1.6.4'
releaseJars 'com.google.guava:guava-collections:r03'
}
Using gradle dependencies gives output such as:
compile - Classpath for compiling the main sources.
+--- org.codehaus.groovy:groovy-all:1.6.4
| +--- junit:junit:3.8.2
| +--- org.apache.ant:ant:1.7.1
| | \--- org.apache.ant:ant-launcher:1.7.1
| +--- org.apache.ant:ant-launcher:1.7.1
| \--- jline:jline:0.9.94
| \--- junit:junit:3.8.1 -> 3.8.2
\--- com.google.guava:guava-collections:r03
+--- com.google.guava:guava-annotations:r03
\--- com.google.guava:guava-primitives:r03
....

Resources