mvn dependency:tree fails on multi-module project due to range version confict - maven-3

I have a multi-module Maven project. The parent pom contains two modules:
moduleA (POM)
moduleB (POM)
moduleA.pom contains three modules:
moduleC (JAR)
moduleD (JAR)
moduleE (WAR)
moduleB depends on C, D and E.
mvn clean package -DskipTests and mvn clean install -DskipTests runs fine but when I ran mvn dependency:tree after these commands, I faced version conflict error:
[ERROR] Failed to execute goal on project moduleB: Could not resolve dependencies for project com.org:moduleB:pom:1.0.0-SNAPSHOT: Failed to collect dependencies for com.org:moduleB:pom:1.0.0-SNAPSHOT: Could not resolve version conflict among [com.org:moduleC:jar:1.0.0-SNAPSHOT -> com.org:test:jar:[1.0.0,1.1.0), com.org:moduleD:jar:1.0.0-SNAPSHOT -> com.org:test:jar:[1.0.0,2.0.0), com.org:moduleE:jar:1.0.0-SNAPSHOT -> com.org:test:jar:[1.1.0,2.0.0)] -> [Help 1]
module C, D and E are not under my control to change above versioning.
I tried some solutions as mentioned here without any success:
mvn dependency:tree fails on trivial project

Related

Failed build - path to project is a directory

The path to my project is /project/
My build file structure is src/main/package/subpackage/Class.java
My test file structure is src/test/package/subpackage/Test.java
I would like my compiled code to be in bin/main/package/subpackage/Class.class
Compiled test code in bin/test/package/subpackage/Test.class
My pom.xml has the entry
<build>
<sourceDirectory>${project.basedir}/src/main</sourceDirectory>
<testSourceDirectory>${project.basedir}/src/test</testSourceDirectory>
<outputDirectory>${project.basedir}/bin/main</outputDirectory>
<testOutputDirectory>${project.basedir}/bin/test</testOutputDirectory>
<finalName>${project.artifactId}-${project.version}</finalName>
</build>
Running mvn clean install causes the following.
Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:2.6:resources (default-resources) on project Hello-Maven: Error loading property file '/project/': /project (Is a directory) -> [Help 1]
...
[Help 1] https://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
Now I've tried the link, but it suggest that it's an issue with the plugins.
However, commenting this block out, and running mvn clean install again returns an almost empty jar file inside /project/target/Hello-Maven-1.0-SNAPSHOT.jar, containing only the pom and the manifest. Additionally, there aren't any plugins, only dependencies: junit and javafx.
EDIT: I realize that plugins specifically for running maven but finding information over why the error happens for "install" is difficult at best.

Jenkins Build Failure, Cobertura Error

I tried to build a job and it returns following error:
> Failed to execute goal
> org.codehaus.mojo:cobertura-maven-plugin:2.7:instrument (default-cli)
> on project addressbook: Execution default-cli of goal
> org.codehaus.mojo:cobertura-maven-plugin:2.7:instrument failed: Plugin
> org.codehaus.mojo:cobertura-maven-plugin:2.7 or one of its
> dependencies could not be resolved: Could not find artifact
> com.sun:tools:jar:0 at specified path
> /var/lib/jenkins/tools/hudson.model.JDK/myjava/../lib/tools.jar ->
> [Help 1]
Any idea how to resolve it?
I guess the jdk in question was above 8 which is still not supported by Cobertura: https://github.com/mojohaus/cobertura-maven-plugin/issues/30
[ERROR] Failed to execute goal
org.codehaus.mojo:cobertura-maven-plugin:2.7:instrument (verification)
on project generex: Execution verification of goal
org.codehaus.mojo:cobertura-maven-plugin:2.7:instrument failed: Plugin
org.codehaus.mojo:cobertura-maven-plugin:2.7 or one of its
dependencies could not be resolved: Could not find artifact
com.sun:tools:jar:0 at specified path
/usr/local/lib/jvm/openjdk11/../lib/tools.jar
I had to switch to https://www.jacoco.org/jacoco/ instead.
Seems like you are missing the tools jar in your JDK/JRE library you can confirm it by searching for the JAR in the lib folder if it's not present then you can add the following in your pom.xml
<dependency>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
<version>1.6.0</version>
<scope>system</scope>
<systemPath>${env.JAVA_HOME}/lib/tools.jar</systemPath>
</dependency>
Where ${env.JAVA_HOME} points to the JAVA you set in environment variables if you are using another JRE apart from the one set then specify the path like so /var/lib/jenkins/tools/hudson.model.JDK/myjava/JDK8/lib/lib
Hope it helps :)

Dependencies Not Resolving with Artifactory , SBT 0.13.6, & Jenkins

Update
If I turn on Anonymous Access in Artifactory then all dependencies are resolved correctly. I am using Artifactory plugin (Generic deployment) and the jenkins user has the read/write permissions on all repositories. Is there anything else that I need to set?
Problem
My CI Build Server is Jenkins. I am trying to create an SBT package and resolve the dependencies using local Artifactory repo.
Followed the instructions from here : http://www.scala-sbt.org/0.13/docs/Proxy-Repositories.html
All dependencies resolve correctly if I don't use the local Artifactory repo. But as soon as I try to use the Artifactory repo, I see the following error :
Blockquote
:: problems summary ::
:::: WARNINGS
module not found: org.scala-sbt#sbt;0.13.6
==== ivy-proxy-releases: tried
http://repo.local:8081/artifactory/ivy-remote-repo/org.scala-sbt/sbt/0.13.6/ivys/ivy.xml
==== maven-proxy-releases: tried
http://repo.local:8081/artifactory/libs-release/org/scala-sbt/sbt/0.13.6/sbt-0.13.6.pom
-- artifact org.scala-sbt#sbt;0.13.6!sbt.jar:
http://repo.local:8081/artifactory/libs-release/org/scala-sbt/sbt/0.13.6/sbt-0.13.6.jar
==== maven-proxy-snapshots: tried
http://repo.local:8081/artifactory/libs-snapshot/org/scala-sbt/sbt/0.13.6/sbt-0.13.6.pom
-- artifact org.scala-sbt#sbt;0.13.6!sbt.jar:
http://repo.local:8081/artifactory/libs-snapshot/org/scala-sbt/sbt/0.13.6/sbt-0.13.6.jar
::::::::::::::::::::::::::::::::::::::::::::::
:: UNRESOLVED DEPENDENCIES ::
::::::::::::::::::::::::::::::::::::::::::::::
:: org.scala-sbt#sbt;0.13.6: not found
::::::::::::::::::::::::::::::::::::::::::::::
The /.sbt/repositories file looks like this :
[repositories]
ivy-proxy-releases: http://repo.local:8081/artifactory/ivy-remote-repo/, [organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext]
maven-proxy-releases: http://repo.local:8081/artifactory/libs-release/
maven-proxy-snapshots: http://repo.local:8081/artifactory/libs-snapshot/
The build.Properties file :
template.uuid=30665618-b7de-4174-aeaa-edf647fee712
sbt.version=0.13.6
The Shell command in Jenkins is :
/usr/lib/jvm/java-8-openjdk-amd64/bin/java -Dsbt.override.build.repos=true -Dsbt.repository.config='.sbt/repositories' -Dsbt.log.noformat=true -jar /opt/sbt-launcher-0.13.6.jar clean clean-files compile dist
What am I missing ?

Running Ant build from Gradle, how to pass -lib argument?

I want to slowly migrate to a better build and dependency resolution process, we are currently using Ant with local file dependencies.
We chose to migrate to gradle ,so as a first step I would like to simply run my current ant build from a gradle sript. But i dont know how to pass the -lib classpath to ant. Im getting errors of missing dependencies.
This is my gradle.build:
apply plugin: 'java'
task someProperties {
ext.LIBS_CATW = "backend/java-src/lib"
ext.LIB_SERVLET = "/usr/local/apache-tomcat-7.0.32/lib/servlet-api.jar"
}
dependencies {
compile files('/usr/local/apache-tomcat-7.0.32/lib/servlet-api.jar')
compile fileTree(dir: 'backend/java-src/lib', include: '*.jar')
}
I use this shell script to run ant from command line.
#!/bin/bash
export JAVA_HOME="/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home"
ROOT_DIR="/Users/poolebu/catwizardMultitenant/catwizard/catwBackend/branches/branchSpringSecurity/"
DIR_MT="$ROOT_DIR"
LIBS_CATW="$ROOT_DIR/backend/java-src/lib"
LIB_SERVLET="/usr/local/apache-tomcat-7.0.32/lib/servlet-api.jar"
ANT_TARGET="allButFlex"
cd $DIR_MT
ant -lib $LIBS_CATW -lib $LIB_SERVLET $ANT_TARGET
This is one of the many dependency errors I´m getting
[ant:javac] /Users/poolebu/catwizardMultitenant/catwizard/catwBackend/branches/branchSpringSecurity/backend/java-src/catw-common/src/com/bamboo/common/factory/SpringFactory.java:5: error: package flex.messaging does not exist
[ant:javac] import flex.messaging.FlexFactory;
[ant:javac] ^

Maven transitive dependencies

I have 3 maven projects: first - "A" with packaging jar, second - "B" packaging jar, third - "C" packaging jar. "C" depends on "B" as compile time dependency, "B" depends on "A" also as compile time dependency. Project "C" also uses classes from "A". So I have transitive dependency C -> B -> A. But when I try to build these projects maven failed with compilation error while compiling project C: it can't find classes from project "A" that is used in "C".
I thought that maven resolves transitive dependency. Why I get such an error?
Maven resolves transitive dependencies, but will not (usually) automatically build them for you. You can get maven to do what you want by supplying the --also-make/-am flag along with the project list:
mvn -am -pl C clean install
This assumes that A, B, C are all modules of a shared parent, and you would be running the command above in the parent's directory.
The failure of transitive dependency in Maven occurs due to many reason. You need to enable debugging option for that.
I faced similar issue. I am using eclipse. To enable debug option for maven in eclipse: Windows->Preference->Maven->Tick mark Debug Output
Error in my project was:
[WARNING] The POM for mil-pop2:java-json:jar:1.0 is invalid, transitive dependencies (if any) will not be available: 4 problems were encountered while building the effective model for mil-pop2:java-json:1.0
[ERROR] 'dependencies.dependency.systemPath' for java-json.jar:java-json.jar:jar must specify an absolute path but is ${project.basedir}/src/main/resources/lib/java-json.jar #
The reason for failure in transitive dependency is the project in which we are dependent inherits the jar from custom path rather than local repository. Remove the custom path if you have provided.
Before :
<dependency>
<groupId>java-json</groupId>
<artifactId>java-json.jar</artifactId>
<version>1</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/lib/java-json.jar</systemPath>
</dependency>
After:
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20090211</version>
</dependency>
This solved my error.

Resources