I am new to Maven, and I am try to deploy my project as a war, and as a jar. I would love to split the project to do the same, but it is too large for simple me to do in a reasonable time.
I found maven deploy additional jar file, which suggested I add some plugins.
The install plugin works great
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>install-file</goal>
</goals>
<configuration>
<packaging>jar</packaging>
<artifactId>${project.artifactId}</artifactId>
<groupId>${project.groupId}</groupId>
<version>SNAPSHOT</version>
<file>
${project.build.directory}/${project.artifactId}-SNAPSHOT.jar
</file>
</configuration>
</execution>
</executions>
</plugin>
Here is the output:
[INFO] [install:install-file {execution: default}]
[INFO] Installing C:\Server\example\code\server\my-project\target\my-project-SNAPSHOT.jar to C:\Users\Kyle\.m2\repository\com\example\main-project\my-project\SNAPSHOT\my-project-SNAPSHOT.jar
The problem is with the maven-deploy-plugin. It seems to ignore the SNAPSHOT version I am forcing it to use:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<executions>
<execution>
<phase>deploy</phase>
<goals>
<goal>deploy-file</goal>
</goals>
<configuration>
<packaging>jar</packaging>
<generatePom>true</generatePom>
<url>${project.distributionManagement.snapshotRepository.url}</url>
<artifactId>${project.artifactId}</artifactId>
<groupId>${project.groupId}</groupId>
<version>SNAPSHOT</version>
<!--${project.version}!="SNAPSHOT" for some reason-->
<file>${project.build.directory}/${project.artifactId}-SNAPSHOT.jar</file>
</configuration>
</execution>
</executions>
</plugin>
Seems to use some other version number (YYYYMMDD.HHmmSS-#)
[INFO] [deploy:deploy-file {execution: default}]
[INFO] Retrieving previous build number from remote-repository
Uploading: http://build.example.biz:8081/artifactory/libs-snapshots-local/com/example/main-project/my-project/SNAPSHOT/my-project-20120625.161551-2.jar
42993K uploaded (my-project-20120625.161551-2.jar)
What am I doing wrong?
One thing i observed is that you are using the version SNAPSHOT without any kind of preceding numbers like:
1.0.0-SNAPSHOT
or at least:
1-SNAPSHOT
You are just using SNAPSHOT this does not make sense, cause of which development line you are talking in this case.
The other thing is that a SNAPSHOT (assuming you are using it in the right way) in Maven is an artifact where a timestamp will be put instead of the SNAPSHOT. That's the way to make it possible having multiple SNAPSHOT being released but make them distinguishable.
So the thing you've showed in your output is exactly what Maven makes out of the SNAPSHOT:
[INFO] [deploy:deploy-file {execution: default}]
[INFO] Retrieving previous build number from remote-repository
Uploading: http://build.example.biz:8081/artifactory/libs-snapshots-local/com/example/main-project/my-project/SNAPSHOT/my-project-20120625.161551-2.jar
42993K uploaded (my-project-20120625.161551-2.jar)
In the respective remote repository there is a http://build.example.biz:8081/artifactory/libs-snapshots-local/com/example/main-project/my-project/SNAPSHOT/maven-metadata.xml. If you have a look at it, you will see that the latest timestamp is mapped to your respective SNAPSHOT. This is typical behavior under both Maven 2 and 3. I believe it's the default behavior under Maven 3 to use timestamped SNAPSHOT-s.
When you try downloading the artifact via Maven, I believe it will resolve it correctly for you, so you shouldn't really be alarmed.
Related
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 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.
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>
This is driving me insane. The Maven failsafe plugin will not run on my project. If I run mvn verify only surefire runs. If I type mvn failsafe:verify it fails with the following error:
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Simulation Experiment Server 1.0
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-failsafe-plugin:2.11:verify (default-cli) # experiment-server ---
[INFO] Failsafe report directory: C:\IdeaProjects\experiment_server\target\failsafe-reports
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.551s
[INFO] Finished at: Fri Mar 30 11:24:58 GMT-06:00 2012
[INFO] Final Memory: 5M/15M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-failsafe-plugin:2.11:verify (default-cli) on project experiment-server: C:\IdeaProjects\experiment_server\target\failsafe-reports\failsafe-summary.xml (The system cannot find the path specified) -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
It's complaining about not finding failsafe-summary.xml. But this should be created by the plugin. And the plugin works fine (and creates the failsafe-summary.xml file if I run run Antonio Goncalves wonderful Arquillian example project.
So I copied the exact plugin information Antonio uses, and it still won't run on my project. I've modelled my POM to be exactly like his (except without a parent pom) -- something must be going wrong, I just don't know what. Why will failsafe run on his project but not mine??
Here is my failsafe pom.xml entry, which is taken right from his, and is the same as the one on the failsafe usaages site):
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>${version.maven.failsafe.plugin}</version>
<configuration>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
Thanks for any help, this is driving me insane.
UPDATE Okay, I seem to have gotten the cannot find failsafe-summary.xml problem fixed -- I change my directory from experiment_server to experiment-server. I guess that messes up failsafe.
But, I'm still having trouble getting failsafe to run from the command mvn verify or mvn integration-test. Both those commands call surefire instead of failsafe. I can now run failsafe directly by using the command: mvn failsafe:integration-test, but shouldn't failsafe automatically run with mvn verify? My mvn help:effective-pom shows that failsafe is there, so that's not the problem... Any ideas?
Take a look at the failsafe docs for the test names failsafe expects by default:
<includes>
<include>**/IT*.java</include>
<include>**/*IT.java</include>
<include>**/*ITCase.java</include>
</includes>
Are your tests named following one of these patterns? If not, try defining the <includes> element in the plugin configuration. Or change your test name(s) to fit the default pattern.
Okay, now that we've verified the test class names - typically when I add executions to plugin config I do it something like this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>${version.maven.failsafe.plugin}</version>
<configuration>
</configuration>
<executions>
<execution>
<id>failsafe-integration-tests</id>
<phase>integration-test</phase>
<goals>
<goal>integration-test</goal>
</goals>
</execution>
<execution>
<id>failsafe-verify</id>
<phase>verify</phase>
<goals>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
This explicitly binds the failsafe plugin goals you want to run to the correct phases of the build lifecycle. I believe the surefire plugin is bound to the test lifecycle phase by default (for a jar, war, & ejb anyway), but nothing is bound to integration-test or verify.
Here I will share my 2 cents. I had same issue and solution above didn't solve my problem.
I had maven-failsafe-plugin encapsulated in pluginManagement tag. I noticed to move it out into plugins tag instead when I saw this doc in the 4.0.0 maven schema:
Default plugin information to be made available for reference by
projects derived from this one. This plugin configuration will not
be resolved or bound to the lifecycle unless referenced. Any local
configuration for a given plugin will override the plugin's entire
definition here.
Hopefully this additional info. solves more ppl's problem like myself.
For me it worked only after I added the "default" includes.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.15</version>
<configuration>
<includes>
<include>**/IT*.java</include>
<include>**/*IT.java</include>
<include>**/*ITCase.java</include>
<include>**/IntegrationTest*.java</include>
</includes>
</configuration>
<executions>
<execution>
<id>failsafe-integration-tests</id>
<phase>integration-test</phase>
<goals>
<goal>integration-test</goal>
</goals>
</execution>
<execution>
<id>failsafe-verify</id>
<phase>verify</phase>
<goals>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
If you are running 2.12.2 version of the failsafe plugin, this is normal. Switch to a previous version. It seem 2.13 is not available yet.
Jira link