Maven: Using different plugin configurations on e.g. deploy - maven

For an android maven project (consisting out of a parent project that consists out of the main apk project and a test project), I would like to be able to use different plugin configurations for building the whole project.
I know that I can do this with profiles, but are there any other options?
The thing I would like to achieve is to execute a deploy with "mvn deploy" and to use a different plugin configuration, that should only be used if a deploy (or release) is taking place.
A concrete example would be to increase the android version code only if a deploy takes place. Binding the increase of the version code directly to the deploy phase does not work as the increased version code is needed before the process-resources phase to work properly.

I'm afraid maven profiles are your only option.
You could add an enforcer check on deploy phase to fail the build if a profile is not active:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>1.2</version>
<executions>
<execution>
<phase>deploy</phase> <!-- enfoce rules on `mvn deploy` -->
<goals>
<goal>enforce</goal>
</goals>
</execution>
</executions>
<configuration>
<rules>
<requireActiveProfile>
<profiles>prod</profiles> <!-- require `-Pprod` -->
</requireActiveProfile>
</rules>
</configuration>
</plugin>

Related

The docker-maven-plugin and jacoco interferes with each other

We have projects where we use jacoco to aggregate code coverage over several modules. We also have some project that use the Fabric8 docker-maven-plugin to run black box test. But for the first time we would now like to run them both i the same project. And it kind of works but not in the same maven command.
We can run mvn test and then jacoco does it job perfecly.
we can run mvn install -Djacoco.skip=true and the black box tests start the necessary docker-containers and run the tests on them.
But running mvn install and thus saying that both blackbox-tests and jacoco codecoverage should run will fail saying that jacoco doesn't find dependencies in a central repository (where they are not supposed to be anyway).
So, my question, what could docker-maven-plugin do to interfere with jacoco? It seems like docker-maven-plugin deletes stuff that jacoco expect to be there.
My configuration for jacoco is using the invoker-plugin (as many of the guides for multi module exampels for jacoco does) with localRepositoryPath, could it be colliding? Or do docker-maven-plugin clean the workspace? Se plugin-definition below.
<plugin>
<!-- To run with different Maven versions use -Dinvoker.mavenHome -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-invoker-plugin</artifactId>
<version>1.5</version>
<configuration>
<skipInvocation>${skipTests}</skipInvocation>
<projectsDirectory>it</projectsDirectory>
<cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo>
<pomIncludes>
<pomInclude>*/pom.xml</pomInclude>
</pomIncludes>
<postBuildHookScript>verify</postBuildHookScript>
<localRepositoryPath>${project.build.directory}/local-repo</localRepositoryPath>
<goals>
<goal>clean</goal>
<goal>install</goal>
</goals>
<settingsFile>it/settings.xml</settingsFile>
<extraArtifacts>
<extraArtifact>org.jacoco:org.jacoco.agent:0.8.3:jar:runtime</extraArtifact>
</extraArtifacts>
</configuration>
<executions>
<execution>
<goals>
<goal>install</goal>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>

Preventing Maven Modules from being Deployed

I followed this tutorial to created a Maven build that can publish artifacts to Maven Central.
It works, and most of the tutorial is for authentication of some sort, so the only relevant part of it might just be:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<executions>
<execution>
<id>default-deploy</id>
<phase>deploy</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
</plugin>
Now I wanted to only deploy two of the seven modules in total, so I added this to the parent POM:
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
And <skip>false</skip> to the two modules I actually want to deploy.
This doesn't work. All modules get deployed.
I checked the effective POM, and it clearly shows skip=false for the two modules I want to deploy and skip=true for the other five modules.
Since deploying to Maven Central isn't really a reversible process, I don't want to trial and error my way through this problem, hence the question: How do I prevent Maven modules from deploying to Maven Central?
If you are deploying to Maven Central, it is the Nexus Staging Plugin that is doing the deployment instead of the Deploy plugin, so the configuration of the deploy plugin has no effect. To make the Nexus deploy plugin skip, set skipNexusStagingDeployMojo in its configuration to true.
For a complete example, you can look at one of my projects I deployed to Maven Central with the same problem - I want to deploy everything except the integration test modules.
In the parent POM, the Nexus deploy plugin is defined like normal as described in the tutorial (https://bitbucket.org/prunge/shoelaces/src/2347535282c9f5bb58d33cca22d9dd65c9db2c2b/pom.xml#pom.xml-200):
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.8</version>
<extensions>true</extensions>
<configuration>
<serverId>ossrh</serverId>
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
<autoReleaseAfterClose>false</autoReleaseAfterClose>
</configuration>
</plugin>
and in the integration tests project (which itself has children that inherit this configuration) the staging plugin is skipped (https://bitbucket.org/prunge/shoelaces/src/2347535282c9f5bb58d33cca22d9dd65c9db2c2b/integration-tests/pom.xml#pom.xml-28):
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<skipNexusStagingDeployMojo>true</skipNexusStagingDeployMojo>
</configuration>
</plugin>
This results in everything by default being deployed to Central except the integration tests project and everything underneath that.

Simultaneously deploy artifact to Maven Central and internal Nexus

I have a project which deploys to Maven Central via OSSRH using the Maven release and nexus-staging-maven plugins using the directions from http://central.sonatype.org/pages/ossrh-guide.html and http://central.sonatype.org/pages/apache-maven.html .
This works fine, but it often takes several hours for the artifact to be visible on Maven Central. Often we would like to make use of the deployed artifact immediately, so we end up deploying it from our local repositories to our internal Nexus server using deploy:deploy-file . This works but it is inelegant and easy to forget to do. Is there any way to make Maven deploy to an internal Nexus as well as Maven Central as part of the release process?
Note: This question is similar to, but not quite the same as, https://stackoverflow.com/questions/29019682/promote-artifact-from-internal-nexus-repository-to-maven-central
Add an additional execution to the maven-deploy-plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>${maven.deploy.plugin.version}</version>
<executions>
<execution>
<id>nexus-deploy</id>
<phase>deploy</phase>
<goals>
<goal>deploy</goal>
</goals>
<configuration>
<altDeploymentRepository>yourNexusRepo</altDeploymentRepository>
</configuration>
</execution>
</executions>
</plugin>
The yourNexusRepo value will look something like this:
releases::default::https://nexus.host.org/nexus/content/repositories/releases
You should be able to get the exact URL from Nexus. The part before the first :: is the repository ID.
We solved this problem by no longer using nexus-staging-maven-plugin as an extension. This is described at https://help.sonatype.com/repomanager2/staging-releases/configuring-your-project-for-deployment :
If more control is desired over when the plugins deploy goal is
activated or if Maven 2 is used, you have to explicitly deactivate the
Maven Deploy plugin and replace the Maven Deploy plugin invocation
with the Nexus Staging Maven plugin...
In our case, we disabled the default-deploy execution by setting <phase>none</phase>. Our full solution is available at https://github.com/newmediaworks/nmw-oss-parent/commit/a7377a158feded473cb2f1618449e34173c22252 which includes an additional execution of maven-deploy-plugin in the jenkins-deploy profile.
The key takeaway follows, which so far seems to behave as if extension were enabled, but does not interfere with additional maven-deploy-plugin executions:
<plugins>
<plugin>
<groupId>org.sonatype.plugins</groupId><artifactId>nexus-staging-maven-plugin</artifactId>
<!--
Not using as extension, since it blocks maven-deploy-plugin in the jenkins-deploy profile:
<extensions>true</extensions>
-->
<executions>
<execution>
<!-- Manually added since nexus-staging-maven-plugin is not used as extension -->
<id>default-deploy</id><phase>deploy</phase><goals><goal>deploy</goal></goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId><artifactId>maven-deploy-plugin</artifactId>
<executions>
<execution>
<!-- Manually disabled since nexus-staging-maven-plugin is not used as extension -->
<id>default-deploy</id><phase>none</phase>
</execution>
</executions>
</plugin>
</plugins>

Eclipse, WebSphere7.0, Maven: AspectJ does not weave code during hot deployment

My System Information:
IDE: Eclipse Blue 10.0,
Server: Websphere 7.0
Build Management Tool: Maven 3.0
I perform compile time weaving in my Maven project using below configuration:
<properties>
<maven.compiler.source>1.6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<!-- <goal>test-compile</goal> -->
</goals>
</execution>
</executions>
<configuration>
<aspectLibraries>
<aspectLibrary>
<groupId>com.xxx.logger</groupId>
<artifactId>my-aspect-logger</artifactId>
</aspectLibrary>
</aspectLibraries>
<showWeaveInfo>true</showWeaveInfo>
<outxml>true</outxml>
<Xlint>warning</Xlint>
<verbose>true</verbose>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
</configuration>
</plugin>
</plugins>
</build>
During development, I use to add my EAR file in exploded mode in Eclipse itself by following below path:
Windows > Show View > Servers > WebSphere 7 > Right Click > Add Deployment
I am facing one issue that whenever I change my java classes those are compiled and hot deployed in server. But, they are not re-weaved. But if I remove the EAR, build my project from command prompt and re-deploy it then it works properly.
Can somebody please help me to resolve this issue.
I'm not familiar with AspectJ but MyEclipse does not execute maven goals to build and deploy projects (though you can add builders, which may invoke maven externally - note that the Maven Project Builder doesn't execute Maven goals), so processing specified in your pom will not be executed automatically, though, obviously, you can run maven goals from the Run As menu item. So changed Java classes will be recompiled using the configured JRE and redeployed. Any additional processing specified in the pom will not be run. However, you say that removing the deployment and then re-deploying actually works, so I'm not sure how the re-weaving gets done, if you don't execute a maven build before redeployment.

What is meant by plugin goal in Maven speak?

I am a newbie to Maven . I am reading up Maven - The complete reference and came across the term Plugin Goals under the Build settings category of a pom.xml file :
In this section, we customize the behavior of the default Maven build.
We can change the location of source and tests, we can add new
plugins, we can attach plugin goals to the lifecycle, and we can
customize the site generation parameters.
Can you please explain with an example what is meant by attaching plugin goal to the lifecycle?
A plugin goal is a thing that a plugin does. Attaching a plugin goal to the lifecycle is saying to maven: when you are going through the lifecycle and are in this phase, trigger this plugin to do whatever the plugin does. This might sound rather confusing, so let's go through an example:
I want to deploy my application to the server each time I call mvn install. For this, in the build section of the pom , I add the following configuration:
<plugin>
<groupId>org.jboss.as.plugins</groupId>
<artifactId>jboss-as-maven-plugin</artifactId>
<version>7.1.1.Final</version>
<configuration>
...
</configuration>
<executions>
<execution>
<id>deploy-jar</id>
<phase>install</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Take a look at the execution part: this describes how to attach the deploy goal of the jboss-as-maven-plugin to the install phase of the build lifecycle.
For further explanation of the maven lifecycle and it's phases, read this

Resources