Maven 3.0.3 - how to check dependency conflict reason - maven-3

Is there an easy way to check what is the reason of dependency conflict in maven 3.0.3? It was easy with maven 2.x by using debug mode (-X switch). Since maven 3.0.3, -X doesn't show dependencies resolution problems.
Maven just produce conflict info without giving the underlying source reason.

With Maven (>= 3.0.0) I use the Sonatype m2eclipse plugin with Eclipse or alternative the latest Spring Tool Suite to graphically visualize the dependency tree and therefore solve any conflict problem. Once the Maven project get imported into the IDE open the POM with the 'Maven POM Editor' and see the 'Dependency Hierarchy' and 'Dependency Graph' tabs.
To import the Maven Project, go to File / Import Project / Maven / Existing Maven Projects.
In order to use your recently downloaded Maven 3.X.Y version instead of the default Eclipse-embedded Maven installation, go to Windows / Preferences / Maven / Installations and Add an external Maven home location. Additionally you shall enable the 'Show advanced tabs in the POM editor' in the section Windows / Preferences / Maven / POM Editor.

For those who use IntelliJ, I recommend Maven Helper plugin. You have a specific section for conflicts, and it even allow you to exclude for resolving conflicts.
In general, you can use mvn dependency:tree > "output.txt" and search in the output file the problematic dependency and see what import it.

Related

How to make Grails get latest local jars from Maven repository?

In my Maven repo (.m2). there is one my local jar like sub_app-0.1.jar.
I have same copy of the it in ivy-cache.
I run maven install on sub_app then new sub_app-0.1.jar file created.
After, I run grails clean and it not getting my new sub_app-0.1.jar from .m2.
But, if I remove (delete) sub_app-0.1.jar file from ivy-cache and run the grails clean then it is getting new sub_app-0.1.jar file into ivy-cache.
If I change the version in sub-app pom and grails pom and Grails is taking latest one. install again it not taking.
I tried by adding SNAPSHOT to sup-app jar even. Same result, first time it is taking, after not.
ie. Grails considering only jar name and version in ivy-cache, if having - it not take. If not having - it taking from .m2.
But it not considering new/old build.
How can I get the same behavior (step 5) in step 4 also?
UPDATED
You can try adding changing=true to your dependency in the BuildConfig.groovy, as specified in the Grails Guide
compile ('YOUR_GROUP_ID:YOUR_SUB_AP:0.1') {
changing = true
}
Not sure if this is the same problem as you, but I use Spring Source Tool Suite (STS) with a 'grails' project having a dependency on an 'interfaces' project (which just contains interfaces, beans, pojos, etc).
If I run a maven install on interfaces in STS, then maven correctly updated with latest jar (I use '-1.0-SNAPSHOT' as my version number).
If I then run a grails clean on my 'grails' project in STS, Grails correctly identifies the change of the interfaces jar (I have {changing=true} in BuildConfig.groovy), downloads the pom, but fails to download the jar as it cannot delete the jar from the ivy-cache. Looks like STS has a handle on the ivy-cache which prevents this.
As I inherited this project from another developer who informed me it was a bug/feature of Grails and/or STS, I've bowed to his knowledge and workaround this by either:
maven package instead of install on 'interfaces' then copy the latest jar to the ivy-cache. It seems STS will let me replace the contents of the jar. Then grails clean uses the latest jar from ivy-cache (no attempt to download from maven).
maven install on 'interfaces', close down STS, delete jar from ivy-cache, re-open STS, grails clean which downloads latest jar from maven.
Both workarounds as a pain, so I'd be interested if anyone has any ideas?
Grails not supports to get latest of same (group-id, artifact-id, version) jar even SNAPSHOT jar also.
Solutions:
Every-time, delete the sub-app-version.jar from ivy-cache. or
Every-time, change the version to next value(should be greater than current value) of the sub-app jar in pom.xml.
4 Configuration - Reference Documentation
Please read:
4.7.6 Snapshots and Other Changing Dependencies

How do I use Hibernate in a dependency of a Grails project (IntelliJ Module dependency)?

I have a Grail application that references a Java library (as an IntelliJ Module dependency). This works, but as soon as I add hibernate as a dependency of the Java library the Grails will no longer run.
Loading Grails 2.0.1
Error Error executing script RunApp: Provider for javax.xml.parsers.SAXParserFactory cannot be found (Use --stacktrace to see the full trace)
In my Java module, I am adding hibernate with the following:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.0.0.Final</version>
</dependency>
I can't see any good way around this. The Grails dependency-report does not show any libraries in conflict. The error occurs if the hibernate plugin is installed in the Grails application or not.
Bear in mind that (in this case) the Java library is not being incorporated via the BuildConfig.groovy. It is being incorporated as an IntelliJ Module dependency. If I incorporate the module as a jar via BuildConfig.groovy, everything works, but I lose the ability to step into the Java code.
Clarifying:
Per the JetBrains folks, the Java library is incorporated both as an IntelliJ Module dependency and in the BuildConfig.groovy. When executed from the command line, the project works, this is only an issue when starting from the IDE.
Suggestions?
Return dependency to java library to BuildConfig.groovy and use last version of IDEA: http://confluence.jetbrains.net/display/IDEADEV/IDEA+11.1+EAP . Navigation should work fine.
After experimentation, I stumbled upon the following which seems to be working very well (at least in IDEA 11.1):
Your Java library JAR should be referenced from the
BuildConfig.groovy (we use Maven, so we had to add the local Maven
repo as well)
Also reference your modules as module dependencies of the Grails module
(this is critical) in the run config for your grails project, uncheck the "add --classpath ..." option
The module dependency gives you:
Immediate awareness of the Java classes and their methods from the Grails project
Support for stepping into the Java code from your Grails project.
The BuildConfig reference gives you:
support for the grails commands, including run-app (which is how IntelliJ kicks things off when running/debugging a project)
If you leave the --classpath option checked, then you foul up the way that grails resolves its dependencies. There may be a better way to do this, but I haven't found it.
Additional Note
There's a bug in the interaction of grails and maven which causes grails to not pull in dependencies from local Maven 3 repositories if the pom.xml wasn't changed.
Therefore, our complete dependency refresh cycle looks like:
goto top
mvn clean install
find the relevant POM files in the repo and touch them
back to grails app directory and grails refresh-dependencies
run the app
You only need to do this when there are updates to the upstream Java libraries.
Hat tip to Sergey from Jet Brains for tracking that one down.

SAXParseException Using Maven-JAXB2 0.7.5 Plugin, Only On Maven 3

I seem to be having issues with the maven-jaxb2-plugin (Version 0.7.5) when using Maven 3. The issue doesn't occur when using Maven 2.2.x, and it only became an issue when I upgraded to Maven 3.
Following is the maven output after executing mvn clean test:
[ERROR] Error while parsing schema(s).Location
[ file:/C:/dev/smart-07-2011/mpg-money-send-service/src/main/resources/META-INF/mpg/schemas/XRSIMoneySend.xsd{218,45}].
org.xml.sax.SAXParseException: src-resolve:
Cannot resolve the name 'common:ResponseBody' to
a(n) 'type definition' component.
However, the tests execute fine when using Maven 2. I've been searching for resources online if there's any known issue between Maven 3 and JAXB2, but I couldn't find any resources. Effective POM for the build using Maven 2 or Maven 3 is identical.
Incidentally, in the past I was able to use the maven-jaxb2-plugin on Maven 3 just fine; this build, however is special in that the XSD is in a dependent JAR, so it could be a configuration issue; but I'm not sure what configuration I would need to set in the POM or bindings.
Are there any resources I could use to resolve this issue, or any resolution steps I could take? Thanks a lot!

Grails Plugin Maven Integration

I'm trying to create Mavenized Grails application. Everything works fine but as I understood all the dependencies (all .jars like mysql-connector and also all grails (public) plugins like spring-security-core plugin) should be listed in pom.xml.
The thing is that I don't know how to include public grails plugins (is there any Maven repository for that, or should I include used plugins into my local repo?). Or is the proper way how to handle grails plugin to list them in "application.properties" and let the grails to manage these plugins?
Thank you for any comment.:-)
Mateo
You can specify your plugin dependencies in grails-app/conf/BuildConfig.groovy, for example:
grails.project.dependency.resolution = {
plugins {
runtime ':hibernate:1.2.1'
}
}
Update
In response to your comments below, a plugin dependency specified in BuildConfig.groovy (or application.properties) will still be resolved by Grails rather than Maven. I don't think there's any way that you can get Maven to resolve a Grails plugin dependency, because Maven can only work with JAR dependencies in Maven repositories. Remember, Grails plugins are not (typically) available from Maven repositories.
If you want to hand as much control as possible over to Maven, you can try excluding the JARs from your plugin dependencies, e.g.
plugins {
runtime( "org.grails.plugins:hibernate:1.2.1" ) {
excludes "javassist"
}
}
and add them to your pom.xml instead. Here be dragons (see below).
Editorializing
FWIW, unless you really have to build your Grails project with Maven (e.g. because another Maven project depends on it), my advice would be don't. I say this because Maven is very much a second-class citizen in the world of Grails build tools. The usual way to build a Grails app is using the built-in GAnt commands. Future versions of Grails will move towards Gradle as the default build tool, so it seems that Maven will be an afterthought for the forseeable future
By default, Grails plugins are included at the source level. A plugin zip is expanded, and the plugin source is compiled as part of the grails build process.
Since 2.0, grails can use binary plugins. You can depend on plain old JARS if those jars represent binary grails plugins.
Binary grails plugins can be referenced by normal maven coordinates.
Your project's BuildConfig.groovy is where you specify maven repositories and binary plugins.

Does Grails + Maven + JCL work in conjunction?

I'm working with IntelliJ IDEA 10.0.1 and Grails 1.3.7. I have a mavenized Grails project which depends on many logging libraries.
Here's the problem:
I have to use JCL as logging framework, but grails per default is working with SLF4J and has some default dependencies like jcl-over-slf4j, which are inherited by every grails project. First of all I have excluded every jcl-over-slf4j transitive dependency in my project pom file and verified with mvn dependency:tree that my pom is clean of any SLF4J bridging libraries.
But nevertheless jcl-over-slf4j is still beeing downloaded to my local maven repo when I try to start my grails app. This leads obviously to a StackOverflowError at runtime, since both jcl-over-slf4j and slf4j-jcl are in the classpath.
So because of which declaration the jcl-over-slf4j dependency is still beeing downloaded?
Since my pom is clean the obvious conclusion would be that Grails itself depends on those libraries. As mentioned before Grails has some default dependencies, on which every Grails project depends.
I know that I can exclude inherited depencencies in the BuildConfig.groovy file and if I run grails dependency-report I can also see that these dependencies are not listed anymore.
grails.project.dependency.resolution = {
inherits("global") {
excludes "jcl-over-slf4j", "jul-to-slf4j", "slf4j-log4j12"
}
}
But even then the jcl-over-slf4j dependency is still beeing downloaded to my repo when I start my grails app! Am I missing something? Is there a different way to exclude inherited grails dependencies when you're using a mavenized grails project?
Any help would be appreciated
Thanks!
Slash
Ok I think I got the answer now..
The problem is that the defined maven-grails-plugin (which is mandatory when you use maven + grails) within my pom file depends on jcl-over-slf4j and therefore gets downloaded when I start my application through maven. With my current maven version (2.2.1) it's not possible to exclude a dependency from a plugin. There is also a jjira issue regarding this problem. Can not exclude a dependency from a plugin
As soon as I remove the maven-grails-plugin the dependency is not downloaded anymore, but as drawback I'm not able to start the application through maven anymore..
Lessons learned: Don't use Maven + Grails + JCL in conjunction.
Note that with mvn dependency:tree just project dependencies are listed, but plugin dependencies are NOT listed.
Hope this is of any help!
Regards Slash

Resources