I have been struggling to fix my maven build issue from last 2 days with no success almost. Can you please help me on this?
I have a parent pom.xml which looks like
<distributionmanagement>
Repository...
Snapshot
<site>
site config here..
</site>
</distributionmanagement>
In child pom.xml, which I wrote works fine if I do 'mvn install'. tar file is created and appears in project/target folder. Looks good so far...
When I do release the problem comes. The good thing is, it goes well till end - creates tar, uploads tar into my svn repository.. but after that maven is trying to read parent pom.xml and error comes while running "maven-site-plugin:default-deploy" and then "BUILD FAILURE"
What I'm thinking is - since tar is created and uploaded into subversion repository creating site & deploying is not required for us. How can I say to maven that once tar is created don't do anything and that's the end point for me. In other words - don't run anything 'site' related stuff for me?
=========================
UPDATE
I have my release plugin config as below
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<configuration>
<tagBase></tagBase>
</configuration>
</plugin>
we actually do release from our batch file which consists of mvn statements like below -
call mvn clean
call mvn install
call mvn -B release:prepare -DdryRun=true -DscmCommentPrefix="somecomment"
call mvn -B release:clean
call mvn -B release:prepare -DscmCommentPrefix="somecomment"
call mvn -B release:perform -DscmCommentPrefix="somecomment"
Can you please suggest me now?
You should change the maven-release-plugin configuration no to do an site-deploy which is default like the following:
<plugin>
<artifactId>maven-release-plugin</artifactId>
<version>2.4.1</version>
<configuration>
<goals>deploy</goals>
</configuration>
</plugin>
Or if creating site & deploying is really not required (as you say in your question), you could just remove the <distributionManagement> section. According to the docs default goals are "either deploy or deploy site-deploy, if the project has a <distributionManagement>/<site> element".
http://maven.apache.org/maven-release/maven-release-plugin/perform-mojo.html
Related
I did download the project from github without any problem, i provided th maven commands mvn clean install and the project build successfully but when it comes to run the tests i get the following error. Any hints? I'am providing my pom.xml file, i tried all the suggestions but nothing.
Does your pom.xml contains the plugin surefire tag ? If thats missing then maven wont download this plugin at runtime and hence the error. Also if its there but maven cant download then may be you have to allow internet connectivity or copy the jars manually inside the .m2 directory on the Jenkins/Node server machine.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.4</version>
</plugin>
I have a java application that is in git repo RepoA and has a scm configuration set up for this repo for maven-release plugin etc.
I want to fetch one file from another RepoB (it is fine to checkout the whole repo also because there is only 1 file there) and use it as a part of build step.
How to do it with maven-scm plugin if scm section is already set up for RepoA?
Thanks.
You can use a separate maven profile for this task.
Here's profile part from pom.xml, assuming that you want to fetch file foo/bar.txt from github repo github-user/some-repo:
<profile>
<id>checkout-foo-bar</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-scm-plugin</artifactId>
<version>1.11.2</version>
<configuration>
<connectionUrl>scm:git:git#github.com:github-user/some-repo</connectionUrl>
<includes>foo/bar.txt</includes>
</configuration>
</plugin>
</plugins>
</build>
</profile>
Then run mvn scm:checkout -P checkout-foo-bar
Plugin first fetches all the files from repo and then removes ones that you don't need. This takes extra time, especially if the repo is huge.
I didn't find a way to setup output directory other than default target/checkout. But hopefully this working example can be a good starting point to solve a problem.
I have a project that uses a JAR with no maven repo.
I made this by myself.
Before build my project, I do this on my console:
mvn install:install-file -Dfile=myownjar-1.5.jar -DgroupId=com.cmabreu -DartifactId=mylocal-lib -Dversion=1.5 -D packaging=jar -DgeneratePom=true
and add the JAR to my maven repo (local).
Then I add the required dependency tag to my POM file and build my project.
But, when I commit to Github, I do not send my custom JAR (is another project).
The question is: how can I tell Travis-CI to build my project using this custom JAR in its repository without send it to Github?
Not a recommended solution but a very useful workaround:
Make a directory inside project's home. Let's call it
$projectBasseDir/lib
Put all your external jars in this folder.
In the pom file add scope and systemPath as follows for your dependency:
< scope>system< /scope >
< systemPath>${project.basedir}/lib/yourJar.jar< /systemPath>
Push this lib/ directory to your project repo on github
Travis builds work fine with this
If the jars are not present locally, then we need to add a before_start script to your repo which basically does this:
mkdir lib/
wget -P "lib/" http://urlForYourJar.jar
and it works great again.
I had a very similar problem and after some research, I did the following.
First of all, add before_install command such as
before_install:
- wget -P somewhere/ http://some.url/awesome.jar
- mvn validate
The line validate is very important, since we need to explicitly install the third-party jar via the maven-install plugin.
The second step is to modify your pom.xml file as follows:
<build>
....
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<groupId>your.group</groupId>
<artifactId>your_artifact</artifactId>
<version>some.version</version>
<packaging>jar</packaging>
<file>${basedir}/match_this_with_wget/awesome.jar</file>
</configuration>
<executions>
<execution>
<id>install-jar-lib</id>
<goals>
<goal>install-file</goal>
<goals>
<phase>validate</validate>
</execution>
</executions>
</plugin>
....
In your local repository, you can put the jar file in the desired place and use .gitignore to avoid committing it into the git repo.
It is also very easy to replace the wget command with other downloading commands such as git clone. However, you may need to put the jar file within your repository if you install it with maven-install. When you are executing the before_install commands on travis-ci, your pwd should be right at your repo root.
If your company has private repo (Artifactory/Nexus) you may want to deploy it there (deploy:deploy-file). This would be one time manual step. Than you wouldn't need to install it into local repo on every build.
If it's not your case, there is no way how to install it into local repo without checking it into your source control.
You can get Travis to run a custom build script. If you can wget the JAR or if you've checked it into your repo, you can run that mvn install command before running your tests yourself.
My Maven project has a bunch of subprojects like this:
proj/
projEAR/
projCommon/
How can I compile and build the EAR project + deploy it to my web server at the same time?
The way I do it now is:
proj$ mvn clean install
[... builds everything ... ]
proj$ cd projEAR
projEAR$ mvn weblogic:deploy
[... deploys the EAR file ... ]
I'd like to do this with one command. Something like
proj$ mvn clean install projEAR/pom.xml weblogic:deploy
This fails of course, but I hope you get the idea...
Update:
The reason for all this is that jenkins only accepts one pom-file and command. So the problem is really how to configure Jenkins to run Maven twice.
How about the weblogic-deployer-plugin of Jenkins. It will deploy your ear file to a weblogic instance. See WebLogic Deployer Plugin.
Quick and easy workaround
As a workaround, I can advise you to use some Jenkin's Plugins, like "M2 Extra Steps". It allow you to perform extra actions pre or post one. They are often use after a build to perform stuff like generating doc, or deploying something.
I know this is working well ... because I often use this trick :)
Suggestion, never tried
At this moment, I don't have a straight answer. I don't really know how to do it in only one maven command. What I would try is to attach weblogic deploy phase to install.
ear submodule --> pom.xml
<build>
[...]
<plugins>
[...]
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>weblogic-maven-plugin</artifactId>
<version>2.9.1</version>
<executions>
<execution>
<configuration>
[...]
</configuration>
<goals>
<goal>install</goal>
</goals>
</execution>
</executions>
</plugin>
[...]
<plugins>
[...]
<build>
It should work, but once again, I never tried it.
Don't hesitate to give feed back
I couldn't get it to work with Maven. But the way I solved it (in Jenkins) was
Create a pre-build step in Jenkins with the command mvn clean install using the parent pom: proj/pom.xml
Configure the main build as weblogic:deploy using projEAR/pom.xml.
This results in two commands being run: First mvn clean install followed by mvn weblogic:deploy.
My SCM connection information:
<scm>
<connection>scm:svn:https://repo/project/trunk</connection>
<developerConnection>scm:svn:https://repo/project/trunk</developerConnection>
</scm>
My release plugin configuration:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<tag>RC</tag>
<autoVersionSubmodules>true</autoVersionSubmodules>
</configuration>
</plugin>
Now when I run mvn release:prepare, instead of committing my tagged release under tags/RC, it does tags/RC/trunk. How do I stop it from adding trunk under RC?
Brian, you may be the victim of Maven's incomplete release:rollback feature. See my question on StackOverflow and the answer to it. If your tag already exists, Subversion (not Maven) will think you want to copy trunk inside the existing tag. Delete the tag and it will work - once. Try again and you'll get RC/trunk. Try yet again and you'll get an error from Subversion.
The solution is to svn delete the tag before you try to copy to it - we do this successfully from Maven during release:perform, by binding a couple of plugins to the deploy phase.
Basically:
Let release:prepare do its thing, create a tag with a unique name.
Bind org.codehaus.mojo:exec-maven-plugin:exec to the deploy phase to make it run during release:perform. Configure it to call svn delete <path to RC tag>.
Bind maven-scm-plugin:branch to deploy in order to create the tag fresh using Maven's SCM plugin.
This works for us and it has the added benefit that it gives us the unique tags too for reference. Worst case, you can ignore these tags.