Jenkins build failure due to use of custom jars in maven project - jenkins

I am having a trouble while building my java maven project in jenkins.
In my project, there are few custom jars which I included in pom like this
<dependency>
<groupId>SMSGatewayClient</groupId>
<artifactId>SMSGatewayClient</artifactId>
<scope>system</scope>
<version>1.0</version>
<systemPath>${basedir}\lib\SMSGatewayClient.jar</systemPath>
</dependency>
But jenkins throwing exception
"Could not find artifact SMSGatewayClient:SMSGatewayClient:jar:1.0 at
specified path
/var/lib/jenkins/workspace/DEV-metal-auc/MetalBusiness_mvn\lib\SMSGatewayClient.jar"
and build is stopped.
How can I use that custom jar so that jenkins builds successfully?

Have you tried using ”/" path separators (or ${file.separator} ) in the path?
Your error shows a mix and /var/lib/ suggests you are on unix.
That assumes the ${basedir} resolved correctly.
You can also use relative notation ( ../ ) and is probably preferred if inside your workspace. You may wish to review Maven complaining about parent relative path and Maven: add a dependency to a jar by relative path
In maven, "${basedir} represents the directory containing pom.xml", so
<relativePath>./lib</relativePath>. If you had to fo up,and down, ../ for each level up, then path down.

Related

Parent POM with Multiple - Multiple Modules having dependency

We had a relative flat project structure in CVS and post migration to Git we encountered a issue due to how Git repository were checkout. A CVS repository was never checkout, but with Git on Eclipse we see a repository folder under which projects are checkout. This has caused issue with our Maven script.
The new structure is:
I added the pom.xml file under idml and leancore that refer to parent pom.xml. the project below idml refers the intermediate idml parent pom.xml and leancore refer intermediate leancore parent pom.xml.
How do I define the dependency between 2 Multiple Modules project?
What will go into the parent POM to support this kind of structure?
How can AdjHubCore refer to a dependency in idml - idmlj2eert?
We would like to build all the module and war file from the root parent pom.xml file.
Your idmlj2eert POM looks like:
...
<groupId>idml</groupId>
<artifactId>idmlj2eert<artifactId>
<version>0.0.1-SNAPSHOT<>version>
...
Then your AdjHubCore looks like:
...
<dependency>
<groupId>idml</groupId>
<artifactId>idmlj2eert<artifactId>
<version>0.0.1-SNAPSHOT<>version>
</dependency>
...
An alternative is to use <dependencyManagement> in your root POM, such avoiding having to declare a dependency's version in child POMs. Your root POM has to be a <parent> POM, direct or transitive across multiple levels, of such a child POM then.
So, that's not different to any other dependency. The Maven Reactor takes care of the proper build order according to (intra-)dependencies inside a multi-module project at the beginning of the build.
Remember, aggregation (multi-module) and inheritance (parent/child relationships) are different things. A project can use either of them and it can use both, too. See POM Reference, Inheritance v. Aggregation and Maven: The Complete Reference, 3.6.2. Multi-module vs. Inheritance.

Worklight ant task using apache commons - where is this loaded from?

I'm trying to diagnose a failure in my ant file when it runs a Worklight task. I have a small ant file containing a simple reference to a Worklight task. This works correctly.
<target name="rawBuildApplication" >
<app-builder
applicationFolder="${applicationSource}"
environments="mobilewebapp"
nativeProjectPrefix="xxx"
outputFolder="${outputFolder}"/>
</target>
However when I invoke this ant file from a build control ant file (actually from the RTC build system) I get a failure (below), showing worklight failing to find an apache Java class. I assume there's some simple environmental difference, perhaps a classpath. It might help to figure it out if I knew where Worklight loaded the apache commons from. Right now I can't see anything in my environment in the case that works that points any apache Jar.
myAntFile.xml:146: java.lang.NoSuchMethodError: org.apache.commons.io.FileUtils.deleteQuietly(Ljava/io/File;)Z
at com.worklight.builder.util.BuilderUtils.<clinit>(BuilderUtils.java:672)
at com.worklight.builder.config.UserBuildConfiguration$Builder.<init>(UserBuildConfiguration.java:203)
at com.worklight.ant.builders.ApplicationBuilderTask.createBuildConfiguration(ApplicationBuilderTask.java:149)
at com.worklight.ant.builders.ApplicationBuilderTask.execute(ApplicationBuilderTask.java:80)
Edited: the cause is the use of -lib to add the RTC toolkit directory, exactly why this clashes and how to work around yet to be determined
Usually means you have version of the commons jar in your classpath, and its overriding the one packaged in the worklight-ant.jar. the apache commons files are inside the worklight-ant.jar file
Additional info from djna: I can confirm that when adding the Rational Team Concert (RTC) 3.0 toolkit to the ant classpath, either explicitly with -lib, or when selecting that option in the RTC Build definition some conflicting commons jars are added to the classpath. Worklight packages the classes it needs in its jar, but the -lib folder seems to take precedence.
My workaround is to replace the conflicting jars with later ones. I used these jars
commons-io-2.4.jar
commons-codec-1.8.jar
httpclient-4.2.5.jar
httpcore-4.2.4.jar
httpmime-4.2.5.jar
I guess the other alternative is to upgrade to a newer RTC, but in our environment that's not currently possible.

How do I make the compile of one maven 3 project depend on the install of another?

I have a directory with a pom.xml and several subdirectories with their own pom.xml files
One subdirectory is local called thirdparty. It contains several jar files and installs them to the local maven repo when a mvn install is executed. These are needed by the mvn compile phase of the other artifacts. The root pom.xml simply executes the same step on each child pom.xml.
I'd like to modify the root pom.xml so that mvn compile will do an install on the third party folder before executing the other folders. I tried this in the maven-compiler-plugin:
<executions>
<execution>
<id>thirdparty</id>
<phase>install</phase>
</execution>
</executions>
I see nothing in the documentation about specifying a phase in a dependency element.
To make sure I have this straight, it sounds like you have an aggregator pom, AGG, and some submodules, A and B, where A is nothing but some third-party jars that have to be installed in the local repo before B will compile. If that's true, then two possibilities spring to mind:
1) Do away with A and instead install the third party jars into an appropriate standalone repo, like a local Nexus server, and add that repo to your pom. That would be the "Maven" way of doing it.
2) Add a dependency on A to B's <dependencies>. In A, configure the install plugin with an execution per jar that needs to be installed, and bind these executions to the compile phase. Then when you run compile on AGG, it will first run compile on A, which will install all the jars, followed by compile on B. Note that this will have the side effect of producing an A.jar, which will be a dependency of B, because maven assumes that every module produces exactly one artifact of some type. You might be forced to add at least one class or resource so that A.jar can actually be built. Not sure about that one. Alternately, you could experiment with setting A's packaging to "pom".
I believe you are using Maven in a wrong way.
Such kind of 3rd party dependencies should be put to local repository (or your internal Maven repository) before you run the compilation work, and dependencies in your project should be setup accordingly. "Installation of 3rd party artifacts" shouldn't be part of the build process.
And, in Maven world, we rarely have 3rd party libs exists as part of the source code. In fact one of the reason for using Maven is to get rid of such kind of libs in source code.
Sounds like you want a couple of dependancies. Look into the depends element.

Can the Cloud Foundry Maven Plugin Work With Multi-Module Aggregator Projects?

I have a standard multi-module maven project and I'm able to build it locally using mvn clean packagebut when I try to deploy it using $ mvn cf:update I get the following error:
[ERROR] Failed to execute goal org.cloudfoundry:cf-maven-plugin:1.0.0.M2:update (default-cli) on project <myprojectname>: An exception was caught while executing Mojo. The file or directory does not exist at '<my project directory>/target/<myprojectname>-SNAPSHOT.war'. -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.cloudfoundry:cf-maven-plugin:1.0.0.M2:update
The problem is that I can't build a .war file for my parent .pom because it needs to be packaged as a pom file, or else maven will reject it. Therefore, I cannot supply the .war file cloudfoundry is looking for. Is there a setting I'm missing?
I'm currently looking into the Maven assembly plugin, but it seems like there should be a more straightforward way to push a multi-module maven project using the maven cloud foundry plugin.
Seems like your parent root either has a single parent pom file or if its a module, it only has a pom inside the target. You are not creating war file inside the target root of your project (if target even exist there). Your application is most likely having each module create their own war files inside their target folders.
At this time I don't think the cf maven plugin would support what you are looking for. could be a enhancement to add a parameter with the module that contains the war file but that is something that needs to be done!
https://github.com/cloudfoundry/vcap-java-client/blob/master/cloudfoundry-maven-plugin/src/main/java/org/cloudfoundry/maven/Update.java
I would recommend you to look into the assembly plugin (which you are already).
Let us know how it goes!

Why is Grails taking the jar dependencies instead of the existing maven project dependencies?

I'm using IntelliJ IDEA 10.0.2 (with groovy/grails support), maven 2.2.1 and grails 1.3.6.
We have a big maven project, which depends on many other maven projects. Let's say the workspace structure looks as follows:
backend-project (Java project, without further project dependencies)
output-project (Java project, without further project dependencies)
frontend-project (Grails project, which dependes on both, backend and output)
That means, within my frontend-project's pom.xml I have defined 2 Project Dependencies:
e.g.
<dependency>
<groupId>com.company.project</groupId>
<artifactId>backend-project</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.company.project</groupId>
<artifactId>output-project</artifactId>
<version>${project.version}</version>
</dependency>
Let's assume that I change some Java Source within the output or backend project. When I
run the grails application now, then it won't consider the changes. I have to publish the changed artifact locally and then resolve it again by the grails project before running the application in order to take effect.
This tells me that the grails project just depends on the project dependency jars within the maven repository and does not care about any existing project dependency "sources" within the workspace.
Does it have to be that complicated and if so, why?
Note that if my frontend project was a spring web project, the changes will be seen in IDEA and tomcat will even reload the change dynamically.
Note that when IDEA recognizes a mavenized grails project, it won't run the grails project with: "grail run-app" anymore but with a more complicated version of: "mvn grails:exec -Dcommand=run-app". Don't know if this is of any relevance..
Thanks!
Mr. Slash
Maven always picks up the jar files from the repositories (local and then remote etc depending on your pom.xml config).
Think about it: How would your main project know where the backend-project or the output-project files are located?
If you want a direct dependency then remove it from pom.xml and modify the project build path to directly add the projects' outputs to your main projects. In Eclipse open the properties page of the main project => build path => projects => add.

Resources