Today I observed a strange behavior in Maven 3 while preparing a release (with the Maven release plugin). As the description tends to be rather long, I would like to ask the question right before the description:
How do I achieve to use the release plugin
so that the build fork executes plugins in the right order
without having multiple executions of same plugins#
and get a valid plugin.xml for the Mojo
The artifact to be released is a Maven plugin itself (Mojo with Annotations). When invoking the release:prepare goal it first starts the process in interactive mode asking for the new version data of the release. After that it forks a new process doing a "clean verify" on the project that's supposed to be released.
As described by the console output the execution order of the invocation is
clean
plugin:descriptor (Maven-plugin-plugin)
resources
compile
testResources
testCompile
test
It seems as if plugin:descriptor is not able to find any Mojos as compilation has not been taken place:
[INFO] [INFO] --- maven-plugin-plugin:3.2:descriptor (default-descriptor) # concordion-maven-plugin ---
[INFO] [WARNING] Using platform encoding (Cp1252 actually) to read mojo metadata, i.e. build is platform dependent!
[INFO] [INFO] Applying mojo extractor for language: java-annotations
[INFO] [INFO] Mojo extractor for language: java-annotations found 0 mojo descriptors.
When configured in the right way, the plugin fails because of no mojo found.
If I configure the release plugin to explicitly invoke the compile goal using
<preparationGoals>clean compile verify</preparationGoals>
the order of plugin execution changes to the following:
clean
plugin:descriptor (Maven-plugin-plugin)
resources
compile
plugin:descriptor (this time finding the Mojo annotation)
resources
compile
testResources
testCompile
test
As the Mojo is found the plugin.xml is created with all the necessary data.
This is the whole build section of my pom.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<showDeprecation>true</showDeprecation>
<showWarnings>true</showWarnings>
<fork>false</fork>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
<version>3.2</version>
<executions>
<execution>
<goals>
<goal>
descriptor
</goal>
</goals>
<phase>prepare-package</phase>
</execution>
</executions>
<configuration>
<skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.4</version>
<configuration>
<dryRun>true</dryRun>
<preparationGoals>clean compile verify</preparationGoals>
<goals>deploy</goals>
</configuration>
</plugin>
</plugins>
</build>
Related
We have been releasing our project via Jenkins pipeline. We have a shared pipeline and the mvn release command executes with options
"'-Dgoals=deploy -DpushChanges=false -DlocalCheckout=true -DpreparationGoals=initialize ' +
'-Darguments="-Dmaven.javadoc.skip=true -Dskip.master=true" -DtagNameFormat="#{project.version}" ' +
'-Dresume=false'".
With one of recent project during maven release phase , it fails stating " Failed to execute goal org.apache.maven.plugins:maven-release-plugin:2.5.3:prepare (default-cli) on project myProject: Cannot prepare the release because you have local modifications :
14:00:25 [main] ERROR org.apache.maven.cli.MavenCli - [myProject/src/main/java/com/schema/avro/GlobalLinePlanStyle.java:modified].
This file is an autogenerated file for avro schema, which is generated by adding the below plugin in pom.xml
<plugin>
<groupId>org.apache.avro</groupId>
<artifactId>avro-maven-plugin</artifactId>
<version>${avro.version}</version>
<configuration>
<sourceDirectory>${project.basedir}/src/main/resources/</sourceDirectory>
<outputDirectory>${project.basedir}/src/main/java/</outputDirectory>
<fieldVisibility>PRIVATE</fieldVisibility>
<includes>
<include>**/*.avsc</include>
</includes>
<testIncludes>
<testInclude>**/*.test</testInclude>
</testIncludes>
</configuration>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>schema</goal>
</goals>
</execution>
</executions>
</plugin>
I have tried adding the explicit maven release plugin in pom.xml as below but that also have not solved the issue
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.5.3</version>
<configuration>
<checkModificationExcludes>
<checkModificationExclude>com/schema/avro/GlobalLinePlanStyle.java</checkModificationExclude>
</checkModificationExcludes>
</configuration>
</plugin>
Since release:prepare expects to find "filters" in checkModificationExcludes configuration setting:
A list of additional exclude filters that will be skipped when checking for modifications on the working copy. Is ignored, when checkModificationExcludes is set.
you need to specify either path relative to project root, i.e.:
<checkModificationExcludes>
<checkModificationExclude>src/main/java/com/schema/avro/GlobalLinePlanStyle.java</checkModificationExclude>
</checkModificationExcludes>
or ant pattern:
<checkModificationExcludes>
<checkModificationExclude>**/com/schema/avro/GlobalLinePlanStyle.java</checkModificationExclude>
</checkModificationExcludes>
BTW, I do not like such setup, because in my opinion generated source files must not reside in the project structure at all, however other developers report they experience other difficulties with proper setup of avro-maven-plugin.
I'm running mvn dependency:analyze-only & im getting the error below. Can someone point me to the correct config for running the maven dependency analyzer?.
FYI, my project builds fine with maven, so im not sure what its looking for. I also listed my pom.xml for the plugin.
this is the error im getting
[INFO]
[INFO] --- maven-dependency-plugin:2.10:analyze-only (default-cli) # MFC ---
[INFO] Skipping project with no build directory
...
This is my pom.xml for the dependency plugin
...
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
<executions>
<execution>
<id>analyze</id>
<goals>
<goal>analyze</goal>
</goals>
<configuration>
<failOnWarning>true</failOnWarning>
<outputDirectory>c:\TEMP\</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
Note that the dependency:analyze-only goal is used in preference to dependency:analyze since it doesn't force a further compilation of the project, but uses the compiled classes produced from the earlier test-compile phase in the lifecycle.
The project's dependencies will then be automatically analyzed during the verify lifecycle phase
If you have not compiled or run your tests before, you will get that message.
Then you must execute as follows
>mvn verify dependency:analyze-only
or simply
> mvn verify
UPDATE
Your pluging goal must be <goal>analyze-only</goal> not <goal>analyze</goal> plugin then must be
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
<executions>
<execution>
<id>analyze</id>
<goals>
<goal>analyze-only</goal>
</goals>
<configuration>
<failOnWarning>true</failOnWarning>
<outputDirectory>c:\TEMP\</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
do the change and execute mvn verify dependency:analyze-only or verify and it should works.
I am trying to get the Maven plugin working to get the dependency-check report. My end goal is to come up with a security-report of the security vulnerabilities on my project.
The Maven snippet which I am using is -
<build>
<pluginManagement>
<plugins>
..
..
<plugin>
<groupId>org.owasp</groupId>
<artifactId>dependency-check-maven</artifactId>
<version>1.4.0</version>
<configuration>
<dataDirectory>/somepath/data</dataDirectory>
</configuration>
<executions>
<execution>
<goals>
<goal>aggregate</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
For my build I am using '
mvn -B -U clean install site:site
However, I don't see the dependency-checks being triggered.
I also tried
mvn -B -U org.owasp:dependency-check-maven:1.4.0:check -Dformat=XML
No luck either. I get an error -
[ERROR] BUILD ERROR [INFO]
------------------------------------------------------------------------ [INFO] Internal error in the plugin manager executing goal
'org.owasp:dependency-check-maven:1.4.0:check': Unable to find the
mojo 'check' (or one of its required components) in the plugin
'org.owasp:dependency-check-maven' Can not set
org.sonatype.plexus.components.cipher.PlexusCipher field
org.sonatype.plexus.components.sec.dispatcher.DefaultSecDispatcher._cipher
to org.sonatype.plexus.components.cipher.DefaultPlexusCipher
Where am I going wrong? Thanks and apologies if the question is way too basic!
Thanks 'A_Di-Matteo' for your help.
Furthermore, I noticed I was using Maven 2 for this build (don't ask me why was it even an option). When I used Maven 3, this problem disappeared.
I have a maven project which builds a WAR and then packs it into a zip file which targets a specific deployment tool. I don't want to upload the WAR as it will be a waste of space.
Is it possible to build the WAR but only upload/deploy the zip in the same pom file?
Edit:
No, the "duplicate" question suggested above does not help the slightest. I have to specify <packaging>war</packaging> and even if I don't, as soon as I use the maven war plugin, it's going to make the war as part of the deployment.
And I also want the other artifacts in the build (source, tests, etc.). I just do not need the war.
Here is a suggested approach to deploy the war or the zip, depending on the need:
The default build will still provide a WAR as output
A profile is added to skip the normal Maven Deploy Plugin execution as part of the deploy phase and add a further execution (obviously not skipped) deploying only the ZIP file via the deploy-file goal, as suggested by #Michal, but not via command line (better as part of the build).
Depending on the need you can of course switch the default behavior from the profile to the default build or even get rid of the default build (just the WAR) at all.
An example:
<build>
<finalName>test-war-zip</finalName>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4.1</version>
<configuration>
<descriptor>src/assembly/descriptor.xml</descriptor>
</configuration>
<executions>
<execution>
<id>create-zip</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>deploy-zip</id>
<build>
<plugins>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
<configuration>
<skip>true</skip>
</configuration>
<executions>
<execution>
<id>deploy-zip</id>
<phase>deploy</phase>
<goals>
<goal>deploy-file</goal>
</goals>
<configuration>
<skip>false</skip>
<file>${project.build.directory}/your.file.here</file>
<repositoryId>your.id.here</repositoryId>
<url>http://something.here</url>
<groupId>${groupId}</groupId>
<artifactId>${artifactId}</artifactId>
<version>${version}</version>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
Note the global configuration for the Maven Deploy Plugin and its skip to true. It will effectively skip the deploy goal. A further execution will take care of the ZIP file.
With the approach above, executing the normal build, Maven will keep on deploying the generated WAR, while switching on the profile as following:
mvn clean deploy -Pdeploy-zip
Maven will skip the default execution of the Maven Deploy Plugin (its deploy goal) and execute instead the deploy-file goal during the deploy phase.
As part of the build you will then have:
[INFO] --- maven-deploy-plugin:2.8.2:deploy (default-deploy) # test-war-zip ---
[INFO] Skipping artifact deployment
[INFO]
[INFO] --- maven-deploy-plugin:2.8.2:deploy-file (deploy-zip) # test-war-zip ---
Uploaded: http://the.repository.here (986 B at 3.9 KB/sec)
When I run $mvn -q clean install, I see a bunch of [debug] execute contextualize statements printed to the console.
After doing some searching, I determined that this is a problem with version 2.5 of the Maven Resources Plugin. This problem has been fixed in version 2.6, but I cant figure out how to get my project to use it. (http://jira.codehaus.org/browse/MRESOURCES-140)
None of my projects have this plugin listed in their poms, so I am not sure where Maven is getting it from, maybe it is used in one of the other Apache dependencies or something? (I don't really even understand what this plugin does or how plugins in Maven are used in general)
I tried adding the following to my root pom:
<build>
<plugins>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
</plugin>
</plugins>
</build>
However, this doesn't seem to solve the problem. I still see the [debug] execute contextualize output and when I run $mvn help:effective-pom, the output still shows:
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.5</version>
<executions>
<execution>
<id>default-resources</id>
<phase>process-resources</phase>
<goals>
<goal>resources</goal>
</goals>
</execution>
<execution>
<id>default-testResources</id>
<phase>process-test-resources</phase>
<goals>
<goal>testResources</goal>
</goals>
</execution>
</executions>
</plugin>
How can I force Maven to use the newer version of this plugin so that I can suppress the annoying [debug] execute contextualize outputs?
Try do add the groupId of the plugin in your build settings :
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
</plugin>
</plugins>
</build>
The maven-resources-plugin is bound to the lifecycle by default for jars, wars, & ears. Adding a definition to your corporate root POM as you did should work to update the version used. Things to check:
Is the inheriting project specifying the version of the corporate parent POM that includes the change?
Did you run mvn clean install on the root POM prior to running the project build?
If the answer is "yes" and "yes", try cleaning out your local artifact repo, then run mvn clean install for the root, and try the build again.