I have two different projects. Project_1 is a maven multi-module project. Project_2 depends on some modules of the Project_2. I have declared a version property in parent POM of Project_1 and referred in the child POM like below.
Project_1 Parent POM
<groupid>x</groupid>
<artifactid>y</artifactid>
<version>${app.version}</version>
<properties>
<app.version>1.0.0</app.version>
</properties>
Project_1 Child POM
<parent>
<groupid>x</groupid>
<artifactid>y</artifactid>
<version>${app.version}</version>
</parent>
<artifactid>y1</artifactid>
Project_2 POM
<dependency>
<groupid>x</groupid>
<artifactid>y</artifactid>
<groupid>1.0.0</groupid>
</dependency>
I have installed Project_1 using "mvn clean install" in the local repository but the problem is Project_1 and its module pom and its dependencies installed in the local repo is with version ${app.version}. Due to this, If I refer the Project_1 or its modules as a dependency in Project_2 with the actual version 1.0.0, its throwing error that it can't find version 1.0.0
Is there any way to solve this? during install of Project_1, I like to override the key {app.version} with actual in the local repo.
The same can be achieved by flatten-maven-plugin.
In case of Parent version include, flatten-maven-plugin can be used with xml-maven-plugin.
I am using the Jenkins version 2.73-1.1 on a CentOS Linux release 7.3.1611 server.
There are 3 different versions of JDK on the server:
[root # jenkins java] # ll
total 12
lrwxrwxrwx. 1 root root 16 27 Apr 16.25 default -> / usr / java / latest
drwxr-xr-x. 8 root root 4096 27 Mar 2013 jdk1.6.0_45
drwxr-xr-x. Root root 4096 11 Apr 2015 jdk1.7.0_80
drwxr-xr-x. 9 root root 4096 27 Apr 16.25 jdk1.8.0_131
lrwxrwxrwx. 1 root root 22 27 apr 16.25 latest -> /usr/java/jdk1.8.0_131
As shown in the pictures below, Jenkins is using the jdk1.8.0_131 version and in my project I specified to use JDK7.
Jenkins setup Image 1
Jenkins setup Image 2
When I try to compile my project (mvn clean deploy), the build fails and I see this ERROR in log:
[Vodafone] $ /usr/java/jdk1.7.0_80/bin/java -cp
/var/lib/jenkins/plugins/maven-plugin/WEB-INF/lib/maven3-agent-1.11.jar:/opt/apache-maven-3.0.4/boot/plexus-classworlds-2.4.jar
org.jvnet.hudson.maven3.agent.Maven3Main /opt/apache-maven-3.0.4
/var/cache/jenkins/war/WEB-INF/lib/remoting-3.10.jar
/var/lib/jenkins/plugins/maven-plugin/WEB-INF/lib/maven3-interceptor-1.11.jar
/var/lib/jenkins/plugins/maven-plugin/WEB-INF/lib/maven3-interceptor-commons-1.11.jar
46349 <===[JENKINS REMOTING CAPACITY]===>channel started ERROR:
================================================================================ ERROR: Invalid project setup: jenkins/security/MasterToSlaveCallable :
Unsupported major.minor version 52.0 ERROR:
[JENKINS-18403][JENKINS-28294] JDK 'JAVA7' not supported to run Maven
projects. ERROR: Maven projects have to be launched with a Java
version greater or equal to the minimum version required by the
master. ERROR: Use the Maven JDK Toolchains (plugin) to build your
maven project with an older JDK. ERROR: Retrying with slave Java and
setting compile/test properties to point to /usr/java/jdk1.7.0_80.
ERROR:
================================================================================ Established TCP socket on 38129 [Vodafone] $
/usr/java/jdk1.8.0_131/jre/bin/java -cp
/var/lib/jenkins/plugins/maven-plugin/WEB-INF/lib/maven3-agent-1.11.jar:/opt/apache-maven-3.0.4/boot/plexus-classworlds-2.4.jar
org.jvnet.hudson.maven3.agent.Maven3Main /opt/apache-maven-3.0.4
/var/cache/jenkins/war/WEB-INF/lib/remoting-3.10.jar
/var/lib/jenkins/plugins/maven-plugin/WEB-INF/lib/maven3-interceptor-1.11.jar
/var/lib/jenkins/plugins/maven-plugin/WEB-INF/lib/maven3-interceptor-commons-1.11.jar
38129 <===[JENKINS REMOTING CAPACITY]===>channel started
Why Jenkins doesn't use jdk 7?
As it is documented on the maven project plugin of jenkins home page:
Jenkins >= 2.54 requires Java 8 thus Maven jobs must be launched with Java >= 8
Luckily the best workaround is just mentioned in your stacktrace:
... Use the Maven JDK Toolchains (plugin) to build your maven project with an older JDK...
In order to compile your project using java 7 and launching successful jenkins job using current jenkins version, I would recommend you to use this plugin by 2 simple steps:
Add toolchains.xml file to your .m2 directory both on developers system and jenkins server
<toolchains>
<toolchain>
<type>jdk</type>
<provides>
<version>1.7</version>
<vendor>openjdk</vendor>
</provides>
<configuration>
<jdkHome>/usr/lib/jvm/java-7-openjdk-amd64</jdkHome>
</configuration>
</toolchain>
<toolchain>
<type>jdk</type>
<provides>
<version>1.8</version>
<vendor>openjdk</vendor>
</provides>
<configuration>
<jdkHome>/usr/lib/jvm/java-8-openjdk-amd64</jdkHome>
</configuration>
</toolchain>
[...]
</toolchains>
Add toolchain plugin to your project pom file
<project>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-toolchains-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<goals>
<goal>toolchain</goal>
</goals>
</execution>
</executions>
<configuration>
<toolchains>
<jdk>
<version>1.7</version>
<vendor>openjdk</vendor>
</jdk>
</toolchains>
</configuration>
</plugin>
</plugins>
</build>
</project>
Finally config your jenkins job to use jdk 8, toolchain will take care of compiling your project with jdk 7.
Try configuring a Freestyle Job in Jenkins. You will need to select the "Invoke top-level Maven targets" build. I was having a similar problem. This worked for me.
I am trying to deploy project artifact into Archiva remote repository but keeps getting this error:
Error Message:
[INFO] --- maven-deploy-plugin:2.8.1:deploy (default-deploy) # mavenandroidapplication ---
Downloading: http://192.168.10.29:8080/archiva/repository/snapshots/com/stm/idg/android/mavenandroidapplication/1.0-SNAPSHOT/maven-metadata.xml
Uploading: http://192.168.10.29:8080/archiva/repository/snapshots/com/stm/idg/android/mavenandroidapplication/1.0-SNAPSHOT/mavenandroidapplication-1.0-20131105.013101-1.apk
Uploading: http://192.168.10.29:8080/archiva/repository/snapshots/com/stm/idg/android/mavenandroidapplication/1.0-SNAPSHOT/mavenandroidapplication-1.0-20131105.013101-1.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.707s
[INFO] Finished at: Tue Nov 05 09:31:01 SGT 2013
[INFO] Final Memory: 16M/39M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.8.1:deploy (default-deploy) on project mavenandroidapplication: Failed to deploy artifacts: Could not transfer artifact com.stm.idg.android:mavenandroidapplication:apk:1.0-20131105.013101-1 from/to archiva.snapshots (http://192.168.10.29:8080/archiva/repository/snapshots/): Access denied to http://192.168.10.29:8080/archiva/repository/snapshots/com/stm/idg/android/mavenandroidapplication/1.0-SNAPSHOT/mavenandroidapplication-1.0-20131105.013101-1.apk. Error code 401, Unauthorized -> [Help 1]
I am using Maven 3.0.5, Archiva 1.3.6, Android Development Kit. This is a maven project and I execute via Run As --> Maven build --> (Goals) deploy.
Below are the configurations:
Settings.xml
Note:
<server>
<id>archiva.internal</id>
<username>admin</username>
<password>123</password>
</server>
<server>
<id>archiva.snapshots</id>
<username>admin</username>
<password>123</password>
</server>
Pom.xml
<distributionManagement>
<repository>
<id>archiva.internal</id>
<name>Internal Release Repository</name>
<url>http://192.168.10.29:8080/archiva/repository/internal/</url>
</repository>
<snapshotRepository>
<id>archiva.snapshots</id>
<name>Internal Snapshot Repository</name>
<url>http://192.168.10.29:8080/archiva/repository/snapshots/</url>
</snapshotRepository>
</distributionManagement>
Really appreciate your help. Thank you.
A few suggestions:
1.) Ensure that you have all your servers listed in your Maven settings.xml. This gets me sometimes.
2.) Ensure that your snapshot repo id matches the repo id defined within Archiva.
3.) Ensure that you have access to the snapshots repo, even as admin. Permissions can be revoked.
4.) Ensure that you have the right password.
5.) I've had a restart of Archiva fix this problem before.
6.) And, finally, ensure that you have the following settings.xml config in place. This solution doesn't quite fit your scenario, but it's good to list nonetheless. The following config will allow you to deploy snapshots to a custom snapshots repo that's part of a repository group (i.e. - a snapshots repo for a particular team):
<mirror>
<id><repo_group_id></id>
<mirrorOf>*, !<team_snapshot_repo_id></mirrorOf>
<name>My Team's Maven Repository</name>
<url>http://<HOST>:<PORT>/archiva/repository/<repo_group_id>/</url>
</mirror>
[INFO] Fork Value is true
[java] The following errors occurred during analysis:
[java] Aug 09, 2013 3:16:04 PM edu.umd.cs.findbugs.TextUIBugReporter reportAnalysisError
[java] SEVERE: Unable to get XClass for java/lang/StringBuilder
...
After these messages Jenkins ends build with failure. On local machine i got these messages too, but nothing interrupts, and findbugs, pmd and checkstyle finish correctly.
Also on Jenkins i got
[PMD] No report found for mojo check
[FINDBUGS] No report found for mojo check
, but on local machine i don't. Seems like these two stranges are linked, how can i fix them?
I run mvn verify.
SCA included in pom.xml in build section like
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>2.5.2</version>
<configuration>
<skip>false</skip>
<failOnViolation>false</failOnViolation>
<failOnError>false</failOnError>
<xmlOutput>true</xmlOutput>
</configuration>
<executions>
<execution>
<phase>verify</phase>
<goals>
<goal>findbugs</goal>
</goals>
</execution>
</executions>
</plugin>
The problem was in different jdks. On local machine i have 1.7, but on Jenkins - 1.8, so i simply changed version. And seems like roots of this bug are in jdk 1.8.
apparently, the class structure changed in Java 8. Therefore, FindBugs version 2.0.3 (latest release as of 1. Mai 2014) and earlier fail on classes compiled on JDK 1.8 (or later). They already fixed this in the FindBugs development version (not released as of 4. May 2014). The latest maven plugin (findbugs-maven-plugin:2.5.3) uses FindBugs 2.0.2.
I decided to generate the maven reports with Java 7, until the fix (and a new FindBugs maven plugin version using it) is released.
to generate the reports with Java 7 (linux):
JAVA_HOME=${HOME}/Software/jdk1.7 mvn site
related FindBugs bug reports:
http://sourceforge.net/p/findbugs/bugs/1271/
http://sourceforge.net/p/findbugs/bugs/1264/
(See edits below.)
The reason I can't just use the classpath, is because I need to manage some non-java libraries, and I'm compiling a non-java project.
I'm trying to use maven dependencies in an antrun call, following the documentation on the maven site:
http://maven.apache.org/plugins/maven-antrun-plugin/examples/classpaths.html
At the bottom of the page:
<property name="mvn.dependency.jar"
refid="maven.dependency.my.group.id:my.artifact.id:classifier:jar.path"/>
<echo message="My Dependency JAR-Path: ${mvn.dependency.jar}"/>
I can't make this work no matter how I try. I've tried ${} around the refid contents, I've tried colons, periods, etc.. as separators in every way I can think of.
Can anyone tell me what that refid should really look like for some common dependency?
EDIT:
Thanks for your reply.
Using your example SingleShot, I have the following:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>create-messages</id>
<phase>compile</phase>
<configuration>
<tasks>
<property name="build.compiler" value="extJavac"/>
<property name="compile_classpath" refid="maven.compile.classpath"/>
<property name="runtime_classpath" refid="maven.runtime.classpath"/>
<property name="test_classpath" refid="maven.test.classpath"/>
<property name="plugin_classpath" refid="maven.plugin.classpath"/>
<property name="log4j.jar" refid="log4j:log4j:jar"/>
<echo message="Where is the Log4J JAR?: ${log4j.jar}"/>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.14</version>
</dependency>
</dependencies>
</plugin>
And here's what I get when run mvn compile:
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building Chat Component
[INFO] task-segment: [compile]
[INFO] ------------------------------------------------------------------------
Downloading: http://<redacted>/content/groups/public/log4j/log4j/1.2.14/log4j-1.2.14.pom
2K downloaded
Downloading: http://<redacted>/content/groups/public/log4j/log4j/1.2.14/log4j-1.2.14.jar
358K downloaded
[INFO] [antrun:run {execution: create-messages}]
[INFO] Executing tasks
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Error executing ant tasks
Embedded error: Reference log4j:log4j:jar not found.
[INFO] ------------------------------------------------------------------------
[INFO] For more information, run Maven with the -e switch
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3 seconds
[INFO] Finished at: Fri Oct 16 14:54:19 PDT 2009
[INFO] Final Memory: 7M/80M
[INFO] ------------------------------------------------------------------------
EDIT (2):
Looking at the sourcecode linked I decided to run "mvn -X compile" and grep for "Storing", which turns up a bunch of log output where things are getting stored.
Of interest are the facts that the dependency I'm explicitly specifying isn't showing in the list, and, that when I switch to a key based on one of the entries I do see, I still get the error.
Based on the code that SingleShot linked to, and random poking until it worked, here's how I got this problem "working", (I say in quotes because it feels very tenuous.)
Here's the way to make it properly work:
<property name="log4j_location"
value="${maven.dependency.log4j.log4j.jar.path}"/>
<echo message="${log4j_location}"/>
Some important things to note: You cannot use the maven dependency as a refid in setting the ant property. You have to use ${} to get the maven var value.
It appears that the dependency must be in the top-level dependency list, making log4j a dependency of the antrun plugin does not expose it to the plugin in anyway that I can see.
All of the path separators are dots (.), no colons (:) which is why I ultimately checked my own answer as correct.
Soapbox:
I would highly recommend anyone considering Maven use Ant with maven plugins or, even better, use Ant with Ivy instead.
This particular problem is a shining example of the utterly absurd level of difficulty associated with doing anything out of the norm with maven.
I say this having implemented an entire build system based on Maven2, and having also implemented several build systems in Ant. I've used both Maven2 and Ant with complex builds involving Java, Flex/AS3, C# and C++. Maven makes sense for Java projects that have no external dependencies on projects in other languages.
Maven does address some things that aren't addressed implicitly by Ant, but with some up front planning, Ant is the much more flexible, better documented, and the less buggy tool.
If you decide to go the ant route, make sure to define a structure for your projects, figure out your dependency system (Use one).
I think you will ultimately be much happier than with Maven, as you won't spend crunch time trying to fix your build system.
As an addendum to Aaron H.'s answer above, I had to set the plugin's version to 1.3 for that to actually work. I was using it without a specific version and was getting 1.1 (where nothing seems to work).
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.3</version>
...
</plugin>
Without an example of what you typed into your POM its hard to say, but consider a concrete example. Let's say your POM references log4j (groupId=log4j, artifactId=log4j). I believe this is how you would reference that JAR in your Ant file:
<property name="log4j.jar" refid="maven.dependency.log4j:log4j:jar.path"/>
<echo message="Where is the Log4J JAR?: ${log4j.jar}"/>
Ideally you shouldn't have to reference specific JARs, but rather, reference the entire classpath for the appropriate scope, as the somewhat sparse documentation for the plug-in indicates.
If you still have trouble, please post the <dependency> tag for a Maven POM dependency you are using and I can try to be more specific.
I looked at the plugin's code to confirm.
This works for me.
<copy file="${javax.mail:javax.mail-api:jar}" todir="tomcat/lib" />
<copy file="${org.springframework:spring-instrument-tomcat:jar}" todir="tomcat/lib" />
<copy file="${postgresql:postgresql:jar}" todir="tomcat/lib"/>
http://maven.apache.org/plugins/maven-antrun-plugin/examples/classpaths.html has the explanation of how to reference dependencies form the ant classpath.
There is a bug in the documentation. The path should be of the form:
<property name="mvn.dependency.jar"
value="${maven.dependency.my.group.id.my.artifact.id.classifier.jar.path}"/>
So the correct key for your log4j dependency would be:
maven.dependency.log4j.log4j.jar.path
Also note that it should be value= rather than refid=, so the full property would be:
<property name="log4j.jar"
value="${maven.dependency.log4j.log4j.jar.path}"/>
<echo message="My Dependency JAR-Path: ${log4j.jar}"/>
I have an existing ant and we planned to use (new) maven to call it. I encountered problems that I may not remember clear, but it is related to class pathes, maybe just like yours.
The problem is, the "ant" we are using daily is a shell script that sets class pathes, both on XNIX and Windows. I have not compared class pathes set by it and those available to maven, but my test showed they dont match and ant won't run with some pathes passed to it from maven.
What I am using is "exec-maven-plugin" and run ant as an external program with some arguments applied. This is sure to work but adds extra dependencies, though.