Skipping deployment for some modules in an aggregate Maven POM - maven

I have an aggregate Maven POM foobar that has several modules including foobar-api and foobar-web. The foobar-web POM actually creates a WAR file, and it uses the tomcat7-maven-plugin to deploy to Tomcat using the tomcat7:deploy goal.
If I bind the tomcat7:deploy goal to the deploy phase, I believe I could do a mvn clean deploy on the foobar-web project and have the WAR be automatically deployed to Tomcat. But if I were to do this on the foobar aggregate POM, wouldn't it complain with "Deployment failed: repository element was not specified in the POM inside distributionManagement element…"?
How could I turn off deployment for certain modules in an multi-module Maven project so that doing a mvn deploy on the aggregate POM would not fail on the non-web projects?
As an alternative, even if I don't bind the tomcat7:deploy goal to the deploy phase, how can I invoke the tomcat7:deploy goal on the aggregate POM and prevent an error for those modules that have no tomcat7-maven-plugin defined?

You probably confused maven deploy phase and goal deploy of tomcat7-maven-plugin.
Maven deploy is phase of maven build lifecycle which is intended to copy result artifacts to remote repository.
More info: https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html
tomcat7:deploy by default is bind to package phase, so if you don't chnge this setting, you can only deploy to tomacat by runing mvn clean package.
If you want stay tomcat7:deploy binding to deploy maven phase you can add in your modules
<properties>
<maven.deploy.skip>true</maven.deploy.skip>
</properties>
but this brake at all maven deployment of those module.

Related

Jenkins maven target war

on my laptop i'm using maven-war-plugin to build me a war file that I later deploy to tomcat
now i'm trying to recreate this build process with Jenkins and the problem that when i set a maven target as war it returns an error msg
[ERROR] Unknown lifecycle phase "war".
how can I use war plugin on jenkins build process ?
Usually, you don't call the war plugin directly, but you call mvn clean install on a project with packaging war. This will trigger all necessary steps, including compilation and also the war plugin.
So put in clean install in your Jenkins and this should be fine.

Installation and deployment of maven test-jar

I've discovered the wonderful test-jar facility in Maven: https://maven.apache.org/plugins/maven-jar-plugin/examples/create-test-jar.html
But it may so happen that one project needs to use the test-jar of another project. From https://stackoverflow.com/a/6469256/421049 and experimentation, it would seem that using mvn install does not install the test-jar to the local ~/.m2/repository. So how does one project on my machine use the test jars of another project not in the same aggregate POM?
Yet it would seem from Maven deploy not to upload test jar that deployment of a project to Maven Central does in fact deploy the test-jar? So I can deploy it to Nexus but not install it locally? And if I deploy it to Nexus, will my local project using a dependency of <type>test-jar</type> go find it on Maven Central?
It turns out that maven-jar-plugin does in fact install the test-jar (e.g. foo-1.2.3-tests.jar) in the local Maven repository ~/.m2/repository/.... Wonderful!
My problem is that I had inadvertently configured the maven-jar-plugin to be in a separate profile named release. (I had copied and pasted to the wrong location in my POM.) That's why the test-jar didn't show up in my local repository after a mvn install, and that's why it suddenly showed up later (after I used -P release once in testing), and I thought I had just missed it when I looked the first time.
I move the maven-jar-plugin to the <build> section and everything is working fine: the test-jar gets put into the local maven repository using mvn install.
In my case, I was setting maven.test.skip for a particular build profile. That property actually causes tests to not be compiled/installed, thus also preventing their deploy. The solution was to set the skipTests property instead.

"mvn clean generate-sources" could not resolve dependencies

there
I met a weird problem. I have a multi-modules enterprise project that is built in Maven. I setup the project hierarchy like this
parentPom
--MyEar (packaging ear)
--MyUtilJar (packaging jar)
--MyEJB (packing ejb)
--MyWeb (packaging war)
In the MyEJB project, the pom.xml actually binds the apt plugin to the generate-sources phase to generate some java codes. MyEJB depends on MyUtilJar project.
My problem is that when I execute the mvn clean compile, everything works fine. But if I execute mvn clean generate-sources instead, it throws error, complaining it cannot resolve dependency for artifact mygroup:MyUtilJar:jar:1.0.
How can I solve this issue?
In order for the generate-sources to work, you need to have all dependencies in a repository - your local one or a remote one. Just having the dependency in a folder near where it's needed won't work.
Try building and installing the until to put it in your local repository then running the generate-sources.

Deploy Artifact to Nexus from Eclipse

Is it possible to run mvn deploy from Eclipse using M2E? I have the distributionManagement section in my pom.xml and the server configured in my settings.xml, but I can't for the life of me see where I can fire of that specific goal.
If the distributionManagement section of your pom is setup properly and pointing to your Nexus, you just need to run the Maven
deploy
goal.
Assuming that you installed the m2eclipse Maven Eclipse plugin, right click your project or your pom, Run As>Maven build and enter the goal "deploy" on the goals line.
If you did not install a Maven Eclipse plugin, add an External Tools configuration pointing to your Maven install for its "Location" and your project dir for its "working directory", with "deploy" as its argument.

Bind mvn jetty:run to a different phase?

I have a maven webapp, which can be run using jetty. If I call jetty with
mvn jetty:run
it is executed before the install phase. However, I want to run jetty at the very end of the maven lifecycle only. How can I achieve that?
Or to put it in a different way. The run goal of jetty maven plugin is bound by default to a certain maven phase. Can I change that binding?
Update: Just to make sure, I don't want to know how to execute jetty automatically each time a maven phase is executed like pre-integration-test. I just want to bind the jetty run goal to a later phase so that additional maven phases get executed when calling it manually.
That's not possible (using predefined packagings like jar or war). In Maven you run plugin's goal or phase (which starts lifecycle). If you run goal, only this goal is executed. If you run phase, lifecycle runs from the beginning to that phase included. Try to run (after mvn clean) mvn install:install (goal only) and then mvn install (default lifecycle to the install phase included).
You can create own plugins' goals to lifecycle's phases binding by creating own packaging type. Predefined packaging types (jar, war, ear, etc.) have this binding already specified.

Resources