How to update Maven3 dependencies in a jenkins Continuous integration environment? - maven

I am using Maven 3 to build my java EAR and Jenkins as CI tool. My maven project is multi-module project that builds a jar, war and EAR.
I am using maven-version-plugin:use-latest-versions goal to update the war dependency in my EAR POM during clean phase.
This updates war dependency version to latest(19.3) version in EAR POM but fails to package the latest WAR(19.3) to EAR.
Maven is using the old version(19.2) of WAR during EAR packaging.How do I configure maven to use latest built dependency?
Thank you in advance
Jenkins Console Output
--- maven-clean-plugin:2.5:clean (default-clean) # EAR ---
[INFO] Deleting EAR\target
[INFO]
[INFO] --- versions-maven-plugin:2.1:use-latest-versions (update-dependency-versions) # EAR ---
[INFO] Major version changes allowed
Props: {project.version=19.3-SNAPSHOT, project.artifactId=EAR, project.groupId=gov.dwd.uplink}
**Updating dependency version from 19.2 to 19.3 in EAR POM**
**[INFO] Updated groupId:App:war:19.2-SNAPSHOT to version 19.3-SNAPSHOT**
[INFO]
[INFO] --- maven-ear-plugin:2.8:generate-application-xml (default-generate-application-xml) # AppEAR ---
[INFO] Generating application.xml
[INFO]
[INFO] --- maven-resources-plugin:2.4.3:resources (default-resources) # AppEAR ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory EAR\src\main\resources
[INFO]
[INFO] --- maven-ear-plugin:2.8:ear (default-ear) # AppEAR ---
**[INFO]Copying artifact [war:groupid:App:19.2-SNAPSHOT] to [App.war]**
This should copy 19.3 not 19.2 version
[INFO] Could not find manifest file: AppEAR\target\AppEAR-19.3-SNAPSHOT\META-INF\MANIFEST.MF - Generatingone
[INFO] Building jar: AppEAR\target\App.ear
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) # AppEAR ---
[INFO] Installing AppEAR\target\App.ear to maven_repo2\GroupID\AppEAR\19.3-SNAPSHOT\AppEAR-19.3-SNAPSHOT.ear
[INFO] Installing AppEAR\pom.xml to D:\CCViews\maven_repo2\GroupID\AppEAR\19.3-SNAPSHOT\AppEAR-19.3-SNAPSHOT.pom
[INFO]
[JENKINS] Archiving disabled
[JENKINS] Archiving disabled
[JENKINS] Archiving disabled
[JENKINS] Archiving disabled

Here is how I fixed my issue with incrementing dependency versions.
I used maven-version-plugin:update-versions to increment the POM version number. Then for dependencies version I used ${project.version}. This keeps POM versions's and dependencies always in sync which helps in CI environment.
Please post if you have a better solution.

Related

Run maven project without testng from Jenkins

I am working on selenium and have created a maven project with user creation and user registration in Eclipse. There is no TESTNG involved in this implementation.
Now, I have created a maven job in Jenkins and configured the pom.xml path and goal set as 'clean install'.
While running this maven job from Jenkins, the build is success but none of the scripts from Eclipse ran for user creation and user registration.
I am seeing the below in the console output in Jenkins against the Job:
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) # GDPortalDemo ---
[INFO] Surefire report directory: C:\RSV\Selenium\GDPortalDemo\target\surefire-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Results :
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[JENKINS] Recording test results
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) # GDPortalDemo---
[WARNING] JAR will be empty - no content was marked for inclusion!
[INFO] Building jar: C:\RSV\Selenium\GDPortalDemo\target\GDPortalDemo-0.0.1-SNAPSHOT.jar
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) # GDPortalDemo---
[INFO] Installing C:\RSV\Selenium\GDPortalDemo\target\HybridSauceDemo-0.0.1-SNAPSHOT.jar to C:\Users\daisy\.m2\repository\GDPortalDemo\GDPortalDemo\0.0.1-SNAPSHOT\GDPortalDemo-0.0.1-SNAPSHOT.jar
[INFO] Installing C:\RSV\Selenium\GDPortalDemo\pom.xml to C:\Users\daisy\.m2\repository\GDPortalDemo\GDPortalDemo\0.0.1-SNAPSHOT\GDPortalDemo-0.0.1-SNAPSHOT.pom
Earlier, I had sure-fire plugin in my pom.xml. I have removed that plugin from pom.xml now and then executed the job.
Can we run a maven job from Jenkins that doesn't have testng tests? In my project, we are not going to use testng. Appreciate any help on this please.

How to find the problem when a maven packaging stage last indefinitely?

I have a fairly large maven project that if compiled (using mvn package or mvn install), stuck on a packaging stage for 10+ hours:
[INFO] Building jar: /home/peng/git-dev/scala-2.11/datapassports/spookystuff/mldsl/target/spookystuff-mldsl-0.6.2-SNAPSHOT-javadoc.jar
[INFO]
[INFO] --- maven-source-plugin:3.1.0:jar-no-fork (attach-sources) # spookystuff-mldsl ---
[INFO] Building jar: /home/peng/git-dev/scala-2.11/datapassports/spookystuff/mldsl/target/spookystuff-mldsl-0.6.2-SNAPSHOT-sources.jar
[INFO]
[INFO] --- maven-source-plugin:3.1.0:test-jar-no-fork (attach-sources) # spookystuff-mldsl ---
[INFO] Building jar: /home/peng/git-dev/scala-2.11/datapassports/spookystuff/mldsl/target/spookystuff-mldsl-0.6.2-SNAPSHOT-test-sources.jar
[INFO]
[INFO] --- maven-jar-plugin:3.0.2:test-jar (default) # spookystuff-mldsl ---
[INFO] Building jar: /home/peng/git-dev/scala-2.11/datapassports/spookystuff/mldsl/target/spookystuff-mldsl-0.6.2-SNAPSHOT-tests.jar
[INFO]
[INFO] --- maven-install-plugin:2.5.2:install (default-install) # spookystuff-mldsl ---
[INFO] Installing /home/peng/git-dev/scala-2.11/datapassports/spookystuff/mldsl/target/spookystuff-mldsl-0.6.2-SNAPSHOT.jar to /home/peng/.m2/repository/com/tribbloids/spookystuff/spookystuff-mldsl/0.6.2-SNAPSHOT/spookystuff-mldsl-0.6.2-SNAPSHOT.jar
[INFO] Installing /home/peng/git-dev/scala-2.11/datapassports/spookystuff/mldsl/.flattened-pom.xml to /home/peng/.m2/repository/com/tribbloids/spookystuff/spookystuff-mldsl/0.6.2-SNAPSHOT/spookystuff-mldsl-0.6.2-SNAPSHOT.pom
[INFO] Installing /home/peng/git-dev/scala-2.11/datapassports/spookystuff/mldsl/target/spookystuff-mldsl-0.6.2-SNAPSHOT-javadoc.jar to /home/peng/.m2/repository/com/tribbloids/spookystuff/spookystuff-mldsl/0.6.2-SNAPSHOT/spookystuff-mldsl-0.6.2-SNAPSHOT-javadoc.jar
[INFO] Installing /home/peng/git-dev/scala-2.11/datapassports/spookystuff/mldsl/target/spookystuff-mldsl-0.6.2-SNAPSHOT-sources.jar to /home/peng/.m2/repository/com/tribbloids/spookystuff/spookystuff-mldsl/0.6.2-SNAPSHOT/spookystuff-mldsl-0.6.2-SNAPSHOT-sources.jar
[INFO] Installing /home/peng/git-dev/scala-2.11/datapassports/spookystuff/mldsl/target/spookystuff-mldsl-0.6.2-SNAPSHOT-test-sources.jar to /home/peng/.m2/repository/com/tribbloids/spookystuff/spookystuff-mldsl/0.6.2-SNAPSHOT/spookystuff-mldsl-0.6.2-SNAPSHOT-test-sources.jar
[INFO] Installing /home/peng/git-dev/scala-2.11/datapassports/spookystuff/mldsl/target/spookystuff-mldsl-0.6.2-SNAPSHOT-tests.jar to /home/peng/.m2/repository/com/tribbloids/spookystuff/spookystuff-mldsl/0.6.2-SNAPSHOT/spookystuff-mldsl-0.6.2-SNAPSHOT-tests.jar
(this is the last line of output)
The build output can be observed on CI server, with similar output:
https://app.codeship.com/projects/166836/builds/48698210?pipeline=103aace8-047a-47e4-9cb9-018c3ce0693a
I don't know what have caused this behaviour, but I suspect that a bug in maven-shade-plugin has caused dependency reduced pom generation to move into a indefinitely loop. How can I confirm this hypothesis collect enough evidence to report to the plugin maintainers?

Downloading ear file from nexus using maven dependency plugin get goal

I am using the maven dependency plugin get goal to download an artefact from nexus. I can use it to download jar as per below
mvn org.apache.maven.plugins:maven-dependency-plugin:2.8:get -DrepoUrl=http://nexus.url/nexus/content/groups/public-all/ -Dartifact=groupId:artifactId:version:jar -Dtransitive=false -Ddestination=/my/path
To download a war I can use
mvn org.apache.maven.plugins:maven-dependency-plugin:2.8:get -DrepoUrl=http://nexus.url/nexus/content/groups/public-all/ -Dartifact=groupId:artifactId:version:war -Dtransitive=false -Ddestination=/my/path
I am however failing to download an ear using the following
mvn org.apache.maven.plugins:maven-dependency-plugin:2.8:get -DrepoUrl=http://nexus.url/nexus/content/groups/public-all/ -Dartifact=groupId:artifactId:version:ear -Dtransitive=false -Ddestination=/my/path
The output of the above command is as per below
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.8:get (default-cli) # standalone-pom ---
[INFO] Resolving groupId:artifactId:ear:version
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.797 s
[INFO] Finished at: 2017-10-20T13:31:02+02:00
[INFO] Final Memory: 7M/19M
[INFO] ------------------------------------------------------------------------
I have confirmed that the ear is indeed present in Nexus. The above command runs successfully but the ear is not actually downloaded.
What is wrong with the above command to download the ear? How can I download an ear file from Nexus using the mvn command?
Do note that I have replaced the actual groupId, artifactId and versions in the code above with their respective words.

Cannot perform 'mvn camel:run' on Camel Example Project

I am new to camel and I've been trying to run one of the examples found in camel called camel-example-twitter-websocket, which may be found here.
When I run mvn compile it works successfully
$ mvn compile
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Camel :: Example :: Twitter WebSocket 2.17-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-enforcer-plugin:1.4:enforce (enforce-maven) # camel-example-twitter-websocket ---
[INFO]
[INFO] --- maven-bundle-plugin:2.3.7:cleanVersions (versions) # camel-example-twitter-websocket ---
[INFO]
[INFO] --- maven-remote-resources-plugin:1.5:process (default) # camel-example-twitter-websocket ---
[INFO]
[INFO] --- maven-resources-plugin:2.7:resources (default-resources) # camel-example-twitter-websocket ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 4 resources
[INFO] Copying 3 resources
[INFO]
[INFO] --- maven-resources-plugin:2.7:resources (default) # camel-example-twitter-websocket ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 4 resources
[INFO] Copying 3 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.5.1:compile (default-compile) # camel-example-twitter-websocket ---
[INFO] Nothing to compile - all classes are up to date
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.504 s
[INFO] Finished at: 2016-03-18T15:27:30-04:00
[INFO] Final Memory: 22M/437M
[INFO] ------------------------------------------------------------------------
But when I run the second step mvn camel:run it does not work and I get the following output
$ mvn camel:run
[INFO] Scanning for projects...
[WARNING] The POM for org.apache.camel:camel-maven-plugin:jar:2.17-20151107.033312-28 is invalid, transitive dependencies (if any) will not be av ailable, enable debug logging for more details
[WARNING] Failed to retrieve plugin descriptor for org.apache.camel:camel-maven-plugin:2.17-SNAPSHOT: Plugin org.apache.camel:camel-maven-plugin: 2.17-SNAPSHOT or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.camel:camel-maven-plugin:jar:2. 17-SNAPSHOT
[WARNING] The POM for org.eclipse.m2e:lifecycle-mapping:jar:1.0.0 is missing, no dependency information available
[WARNING] Failed to retrieve plugin descriptor for org.eclipse.m2e:lifecycle-mapping:1.0.0: Plugin org.eclipse.m2e:lifecycle-mapping:1.0.0 or one of its dependencies could not be resolved: Failure to find org.eclipse.m2e:lifecycle-mapping:jar:1.0.0 in https://repo.maven.apache.org/maven2 w as cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced
[WARNING] The POM for org.apache.maven.plugins:maven-surefire-plugin:jar:{maven-surefire-plugin-version} is missing, no dependency information av ailable
[WARNING] Failed to retrieve plugin descriptor for org.apache.maven.plugins:maven-surefire-plugin:{maven-surefire-plugin-version}: Plugin org.apa che.maven.plugins:maven-surefire-plugin:{maven-surefire-plugin-version} or one of its dependencies could not be resolved: Failure to find org.apa che.maven.plugins:maven-surefire-plugin:jar:{maven-surefire-plugin-version} in https://repo.maven.apache.org/maven2 was cached in the local repos itory, resolution will not be reattempted until the update interval of central has elapsed or updates are forced
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-metadata.xml
Downloading: https://repository.apache.org/content/repositories/snapshots/org/apache/maven/plugins/maven-metadata.xml
Downloading: https://repo.maven.apache.org/maven2/org/codehaus/mojo/maven-metadata.xml
Downloading: https://repository.apache.org/content/repositories/snapshots/org/codehaus/mojo/maven-metadata.xml
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-metadata.xml (13 KB at 36.9 KB/sec)
Downloaded: https://repo.maven.apache.org/maven2/org/codehaus/mojo/maven-metadata.xml (20 KB at 57.4 KB/sec)
Downloaded: https://repository.apache.org/content/repositories/snapshots/org/apache/maven/plugins/maven-metadata.xml (9 KB at 9.7 KB/sec)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.140 s
[INFO] Finished at: 2016-03-18T15:28:29-04:00
[INFO] Final Memory: 27M/327M
[INFO] ------------------------------------------------------------------------
[ERROR] No plugin found for prefix 'camel' in the current project and in the plugin groups [org.apache.maven.plugins, org.codehaus.mojo] availabl e from the repositories [local (C:\Users\myNameHere\.m2\repository), apache.snapshots (https://repository.apache.org/content/repositories/snapshots/), central (https://repo.maven.apache.org/maven2)] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/NoPluginFoundForPrefixException
It looks like this is more of a Maven issue than it is a Camel issue. I put in the default .m2/settings.xml file (before I had a mirror configured for my companies Nexus repository. I thought that might be messing things up so I took it all out). Out of desperation I even tried adding in the plugin repository from here http://camel.apache.org/maven-2-snapshot-repository-in-pom.html but that did not work.
Read the readme file how to run the examples.
Some examples run using mvn camel:run and others using mvn exec:java and what else.
And you run from the master branch in the source code. Instead you should download a version of Camel such as the latest 2.16.2 and use that. It ships the examples in the examples directory: http://camel.apache.org/download
If you run from master branch in the source code. You need to rebuild Camel first, see building: http://camel.apache.org/building.html
I've tested myself, and putting the plugin 2.16 don't solve it neither.
But in readme, I found this :
We have described this in more details at the Camel twitter documentation:
http://camel.apache.org/twitter
You will need to compile this example first:
mvn compile
To run the example type
mvn exec:java
Then open a browser to see live twitter updates in the web page
http://localhost:9090
Worked for me, I hope it will work for you too. I'll investigate the problem with the plugin that doesn't seems to export the prefix latter.

Maven - Reactors (Aggregation)

I have a maven project with a following directory structure:
trunk
| pom.xml
| coreutils
| | pom.xml
| | src
| budgetCap
| | pom.xml
| | src
The content of trunk/pom.xml is :
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
hxttp://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>Ant2Maven</groupId>
<artifactId>parent</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<name>Parent Pom</name>
<modules>
<module>coreutils</module>
<module>budgetCap</module>
</modules>
In this structure, "budgetCap" is dependent on "coreutils",i.e. pom.xml of "budgetCap" contains a dependency of "coreutils"
Now I have two methods to build this project
First Method
Aggregation using Reactor
I will be inside trunk
So first of all I do mvn clean
shakim:trunk shakim.md$ mvn clean
Maven deletes the target folder of the two module in this order:
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] coreutils
[INFO] budgetCap Maven Webapp
[INFO] Parent Pom
Now when i do mvn install
shakim:trunk shakim.md$ mvn install
Maven starts building modules in the following order:
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] coreutils
[INFO] budgetCap Maven Webapp
[INFO] Parent Pom
In the given order, coreutils gets installed in the local repository successfully.
But budgetCap fails at the compilation giving an error that maven is unable to locate a class which was supposed to be produced by coreutils
the error message is as follows:
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building budgetCap Maven Webapp 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # budgetCap ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 4 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) # budgetCap ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 65 source files to /Users/shakim.md/shakim/maven/ops/adq_services/trunk/budgetCap/target/classes
[INFO] -------------------------------------------------------------
[WARNING] COMPILATION WARNING :
[INFO] -------------------------------------------------------------
[WARNING]/Users/shakim.md/shakim/maven/ops/adq_services/trunk/budgetCap/src/main/java/com/adiquity/budgetCap/core/SingletonAggregator.java: /Users/shakim.md/shakim/maven/ops/adq_services/trunk/budgetCap/src/main/java/com/adiquity/budgetCap/core/SingletonAggregator.java uses unchecked or unsafe operations.
[WARNING]/Users/shakim.md/shakim/maven/ops/adq_services/trunk/budgetCap/src/main/java/com/adiquity/budgetCap/core/SingletonAggregator.java: Recompile with -Xlint:unchecked for details.
[INFO] 2 warnings
[INFO] -------------------------------------------------------------
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /Users/shakim.md/shakim/maven/ops/adq_services/trunk/budgetCap/src/main/java/com/adiquity/budgetCap/core/BudgetCapServer.java:[41,34] package com.adiquity.request.utils does not exist
[ERROR] /Users/shakim.md/shakim/maven/ops/adq_services/trunk/budgetCap/src/main/java/com/adiquity/budgetCap/utils/Utils.java:[9,34] package com.adiquity.request.utils does not exist
[ERROR] /Users/shakim.md/shakim/maven/ops/adq_services/trunk/budgetCap/src/main/java/com/adiquity/budgetCap/log/data/parser/ConversionParser.java:[16,34] package com.adiquity.request.utils does not exist
Briefly speaking this package package com.adiquity.request.utils is actually present in coreutils, which this module budgetCap must have located successfully, but it is not.
Second Method
Go inside coreutils and do a
shakim:coreutils shakim.md$ mvn clean install
Go inside budgetCap and do a
shakim:budgetCap shakim.md$ mvn clean install
budgetCap compiles successfully without reporting any kind of error.
My question is that I want to use Reactors in Maven and I am unable to figure out why the build fails on using 1st method whereas 2nd method of building completes smoothly??
I am not sure how to use reactors, do we need to include anything in pom of coreutils and budgetCap signifying that pom of trunk is the parent.
Note: I don't want to use inheritance in this project

Resources