I have a third party jar which is necessary for our project. It is not available on the central maven repository, so I used the maven-install-plugin to install the jar locally during a build. I tied the "install-file" goal to the "validate" phase, and this mostly works. The pom.xml file excerpt is below:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<id>install-myartifact</id>
<phase>validate</phase>
<goals>
<goal>install-file</goal>
</goals>
<configuration>
<file>${basedir}/lib/myartifact-1.2.3.jar</file>
<groupId>com.example</groupId>
<artifactId>myartifact</artifactId>
<version>1.2.3</version>
<packaging>jar</packaging>
<generatePom>true</generatePom>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.example</groupId>
<artifactId>myartifact</artifactId>
<version>1.2.3</version>
</dependency>
</dependencies>
However, there's a catch. Most of our developers and our Jenkins installation run "mvn clean install." The "validate" phase is not part of the "clean" lifecycle, and clean inexplicably requires all the dependencies be present to run. So the first time someone runs this build, it does not work.
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building MyModule
[INFO] task-segment: [clean, install]
[INFO] ------------------------------------------------------------------------
[INFO] [clean:clean]
[INFO] Deleting directory C:\svn\trunk\mymodule\target
Downloading: http://nexusserver.local:8080/nexus/content/groups/public/com/example/myartifact-1.2.3.pom
[INFO] Unable to find resource 'com.example:myartifact:pom:1.2.3' in repository central (http://central)
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Failed to resolve artifact.
Missing:
----------
1) com.example:myartifact:jar:1.2.3
Try downloading the file manually from the project website.
Then, install it using the command:
mvn install:install-file -DgroupId=com.example -DartifactId=myartifact -Dversion=1.2.3 -Dpackaging=jar -Dfile=/path/to/file
Alternatively, if you host your own repository you can deploy the file there:
mvn deploy:deploy-file -DgroupId=com.example -DartifactId=myartifact -Dversion=1.2.3 -Dpackaging=jar -Dfile=/path/to/file -Durl=[url] -DrepositoryId=[id]
Path to dependency:
1) com.example:mymodule:war:0.0.1-SNAPSHOT
2) com.example:myartifact:jar:1.2.3
----------
1 required artifact is missing.
for artifact:
com.example:mymodule:war:0.0.1-SNAPSHOT
from the specified remote repositories:
nexus (http://nexusserver.local:8080/nexus/content/groups/public)
[INFO] ------------------------------------------------------------------------
[INFO] For more information, run Maven with the -e switch
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1 second
[INFO] Finished at: Thu Jun 09 11:01:24 EDT 2011
[INFO] Final Memory: 17M/247M
[INFO] ------------------------------------------------------------------------
If I were to run simply "mvn install", the jar is installed during "validate," and I can run "mvn clean install" in subsequent builds. However, our build server does not have that flexibility. I've considered the following:
Moving the phase to "pre-clean," but that assumes everyone always uses clean the first time. It wouldn't help if someone ran simply "mvn install."
Copying the execution, with one occurring during "pre-clean" and one occurring during "validate." This covers all the bases, but the copied code leaves a bad taste.
Ideally, I'd love some other option. Is it possible to run clean without dependencies? Or to run a plugin twice without having to fully copy the execution? Thanks!
I ran into a related issue, and I found this question when googling for a solution, so I'll note it here:
mvn clean fails in a multi-module project when there are missing dependencies within the same project, if plugins are invoked during clean.
We invoke the antrun-plugin during the clean phase in some modules, and because of that all dependencies need to be present in the maven repository, including the other modules in the same reactor, which in some cases have not been built yet (say you just bumped the project version, or you're starting off a new project).
This is a maven-antrun bug reported in https://issues.apache.org/jira/browse/MANTRUN-78 - which again leads back to a bug in maven core: https://issues.apache.org/jira/browse/MNG-3283.
My workaround was to provide the developers (and Jenkins) with an alternative way of doing clean (shell/bat script, ant script or some git/hg clean operation), and have them invoke this instead.
I would suggest a similar workaround for your team (or just set up up a shared maven repository internally in your team, use one of the developer machines if necessary).
It looks like you're using nexus. It might be easier to deploy the artifact to the nexus repo as opposed to having to maintain it with this project.
This is untested, but can you not ignore the error from the clean plugin's configuration? As in:
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.4.1</version>
<configuration>
<failOnError>false</failOnError>
</configuration>
</plugin>
(This is from Maven Clean Plugin : Ignoring Clean Errors)
Here is one more possibility.
Configure maven to skip clean phase and run clean during initialize. Have not tried this though.
The drawback of this is maven will always clean the output folders.
Related
I added plugin in my pom.xml
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>2.9</version>
</plugin>
I would like to generate raport about licenses of dependency in my project.
How to do it ?
Launching goal: info-reports-plugin:dependencies by IDEA doesn't help. It returns in console:
[INFO] --- maven-project-info-reports-plugin:2.9:dependencies
(default-cli) # myApp [WARNING] The repository url
'http://download.java.net/maven/2' is invalid - Repository
'm2.dev.java.net' will be blacklisted. [WARNING] The repository url
'http://people.apache.org/repo/m2-snapshot-repository' is invalid -
Repository 'apache.snapshots' will be blacklisted.
I can't see anywhere report.
I have project A which a pom.xml dependency of:
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-email</artifactId>
<version>1.2</version>
</dependency>
commons-email depends on javax.mail-1.4.1
I ran mvn install to install projectA.jar into the local maven repo.
In project B, i depend projectA.jar.
When I run project B, it fails due to a missing class file in javax:
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]
java.lang.ClassNotFoundException: com.sun.mail.smtp.SMTPTransport
How can i run project B successfully without explicitly putting a maven entry for the javax.mail jar?
EDIT:
I think I found the problem.
I was using maven-shade-plugin with true and it was removing the org.apache.commons:commons-email:jar dependencies in installed(.m2) project A pom file.
Commenting out the maven-shade-plugin for project A fixed the dependency problem.
How can i run project B successfully without explicitly putting a maven entry for the javax.mail jar?
Well, that's weird. c.s.m.s.SMTPTransport is supposed to be provided by mail-1.4.1.jar which is a dependency of commons-email. Project B should get it transitively.
Could you run the following on project B and post the output
mvn dependency:tree
Update: There is definitely something weird with your dependencies and I can't reproduce the problem.
I quickly created a first project with the following pom:
<project>
...
<groupId>com.stackoverflow</groupId>
<artifactId>Q3875317-A</artifactId>
<dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-email</artifactId>
<version>1.2</version>
</dependency>
</dependencies>
</project>
And another one depending on the first artifact:
<project>
...
<groupId>com.stackoverflow</groupId>
<artifactId>Q3875317-B</artifactId>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>Q3875317-A</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
And here is the dependency tree I get for the second project:
$ mvn dependency:tree
[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'dependency'.
[INFO] ------------------------------------------------------------------------
[INFO] Building Q3875317-B
[INFO] task-segment: [dependency:tree]
[INFO] ------------------------------------------------------------------------
[INFO] [dependency:tree {execution: default-cli}]
[INFO] com.stackoverflow:Q3875317-B:jar:1.0-SNAPSHOT
[INFO] +- com.stackoverflow:Q3875317-A:jar:1.0-SNAPSHOT:compile
[INFO] | \- org.apache.commons:commons-email:jar:1.2:compile
[INFO] | +- javax.mail:mail:jar:1.4.1:compile
[INFO] | \- javax.activation:activation:jar:1.1:compile
[INFO] \- junit:junit:jar:3.8.1:test
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
...
Everything is there, as expected.
If you get a different result and if there is anything noticeable about your POMs, please show them.
PS: I removed one of the command I initially suggested as it didn't allow to see transitive dependencies.
hey,
I have a deploy pojo plugin (deploying a war to a remote server). I have the remote-deploy plugin in the build section of pom definition, I need package phase to be triggered before deploy-remote goal, for it the war be already created before I secure-copy it to a remote server.
With the execution elements (according to a documentation), I can attach my goal to a particular phase, for instance bind it to the phase after, so in my case, install phase ...but that's just a workaround.
<build>
<plugins>
<plugin>
<groupId>sample.plugin</groupId>
<artifactId>maven-hello-plugin</artifactId>
<version>1.0-SNAPSHOT</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>sayhi</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
simply put, if I place only my goal into the build section, and run it, package phase is not run before. Please help
Maven Mojo plugin, how to define phases that must be triggered before this goal ?
You can't.
I have the remote-deploy plugin in the build section of pom definition, I need package phase to be triggered before deploy-remote goal, for it the war be already created before I secure-copy it to a remote server.
Just bind it to the package phase, your goal will be called after the goals bounds to package by default (so the war will be there).
Here is an example demonstrating this behavior with the Maven AntRun plugin configured like this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<phase>package</phase>
<configuration>
<target>
<echo message="Hi!!!!!"/>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
And the output of mvn package:
$ mvn package
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Q3934833 Maven Webapp 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
...
[INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) # Q3934833 ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-surefire-plugin:2.5:test (default-test) # Q3934833 ---
[INFO] No tests to run.
[INFO]
[INFO] --- maven-war-plugin:2.1:war (default-war) # Q3934833 ---
[INFO] Packaging webapp
[INFO] Assembling webapp [Q3934833] in [/home/pascal/Projects/stackoverflow/Q3934833/target/Q3934833]
[INFO] Processing war project
[INFO] Copying webapp resources [/home/pascal/Projects/stackoverflow/Q3934833/src/main/webapp]
[INFO] Webapp assembled in [317 msecs]
[INFO] Building war: /home/pascal/Projects/stackoverflow/Q3934833/target/Q3934833.war
[INFO] WEB-INF/web.xml already added, skipping
[INFO]
[INFO] --- maven-antrun-plugin:1.6:run (default) # Q3934833 ---
[INFO] Executing tasks
main:
[echo] Hi!!!!!
[INFO] Executed tasks
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
...
The antrun plugin is executed after package, as expected.
You can try use PREPARE_PACKAGE phase in your #Mojo annotation:
#Mojo(name = "myName", defaultPhase = LifecyclePhase.PREPARE_PACKAGE)
I am trying to release a web project using Maven 2.2.1 and the maven-release-plugin 2.0-beta-9, but it always fails when doing release:perform on generating the sources jar for the EAR project, which makes sense since the EAR project doesn't have any source.
[INFO] [INFO] [source:jar {execution: attach-sources}]
[INFO] [INFO] ------------------------------------------------------------------------
[INFO] [ERROR] BUILD ERROR
[INFO] [INFO] ------------------------------------------------------------------------
[INFO] [INFO] Error creating source archive: You must set at least one file.
To try to disable the building of a sources JAR for the EAR project, I added the following to the POM for my EAR project (the version of the release plugin is set in a parent POM):
<build>
<plugins>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<configuration>
<useReleaseProfile>false</useReleaseProfile>
</configuration>
</plugin>
</plugins>
</build>
Upon running the release again after checking in this change, I got the same error while generating the sources JAR for the EAR project, even though this should have been disabled by the previous POM snippet.
What am I doing wrong? Why is the sources JAR still being built?
Edit:
I've tried to make the source plugin include my application.xml file so that this error doesn't occur by adding the following POM snippet:
<build>
<plugins>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<configuration>
<includes>
<include>${basedir}/META-INF/**/*</include>
</includes>
<useDefaultExcludes>false</useDefaultExcludes>
</configuration>
</plugin>
</plugins>
</build>
Unfortunately, this does not fix the problem either.
I finally figured it out. I needed to add my source files as part of the references:
<resources>
<resource>
<directory>${project.basedir}</directory>
<includes>
<include>META-INF/**/*</include>
</includes>
<excludes>
<exclude>target/**/*</exclude>
<exclude>bin/**/*</exclude>
<exclude>META-INF/.svn/**/*</exclude>
</excludes>
</resource>
</resources>
Doing this made everything work again. I didn't need any special configuration for the release or source plugins to get it to work.
There was a bug in the maven-source-plugin version 2.1 that resulted in the same error as you describe here. Newer Version >= 2.1.1 contain the fix. Here is a link to this Bug for further information. http://jira.codehaus.org/browse/MSOURCES-44
I use nexus opensource version maven 2.2.1
When I type "mvn help:effective-settings", i got the error below
[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'help'.
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Error building POM (may not be this project's POM).
Project ID: org.apache.maven.plugins:maven-help-plugin
Reason: Error getting POM for 'org.apache.maven.plugins:maven-help-plugin' from the repository: Failed to resolve artifact, possibly due to a repository list that is not appropriately equipped for this artifact's metadata.
org.apache.maven.plugins:maven-help-plugin:pom:2.2-SNAPSHOT
from the specified remote repositories:
Nexus (http://192.168.56.191:8081/nexus/content/groups/public)
for project org.apache.maven.plugins:maven-help-plugin
When I check the local repository under ~.m2\repository\org\apache\maven\plugins\maven-help-plugin
It has a file maven-metadata-central.xml
<?xml version="1.0" encoding="UTF-8"?>
<metadata>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-help-plugin</artifactId>
<versioning>
<latest>2.2-SNAPSHOT</latest>
<release>2.1.1</release>
<versions>
<version>2.0</version>
<version>2.0.1</version>
<version>2.0.2</version>
<version>2.1</version>
<version>2.1.1</version>
<version>2.2-SNAPSHOT</version>
</versions>
<lastUpdated>20100519065440</lastUpdated>
</versioning>
</metadata>
And I can't find any jar files under directory, what's wrong with nexus server ? I can't easily find support information from nexus.
Any hints
It's definitely as Brian said. You probably have only mirrored repositories without doing the hack with setting up the profile as nexus documentation says with those bogus central URLs. If you run maven in debug mode, you would see things like "Skipping disabled repository central". - disabled refers to the policy that applies for a specific artifact.
Because you want SNAPSHOT artifact which probably has the relevant policy <snapshots> <enabled>true</enabled> and maven central has <snapshots> <enabled>false</enabled> it doesn't work without the hack in the nexus documentation.
Mirror only replaces the URL, it doesn't change the policies of the original repositories, but for a repo manager to work, one usually wants to redirect both release and snapshot artifact requests
Hope it helps to clarify this issue, it's good to know about it
It looks like you might have your settings.xml misconfigured. Try setting like like this, and if you still have trouble, ask us on the nexus-user list and we'll go from there.