问题
I want to split my continous integration job (Hudson) into two steps. (Because the runtime with build and reporting together takes too long.) In the first job, I build my multi module maven project with "mvn package" successfully. Then I copy my workspace to another location and try to build the project again only with the goal "site" and/or findbugs/checkstyle/pmd to create reports. But this doesn't work! Maven can't resolve a dependency of my submodules. (But all JARs are available in its target folders.)
Example: My structure looks like this:
- Parent
- A
- B
- C
- D
Project C has as dependency project B.
When I build everything with "mvn site", it generates for project A and B all reports. But halted at project C with error message "Could not resolve dependencies for project B." But project B is already builded with "mvn package". I.e. I can find the JAR file of project B in its target folder.
Is there any way to resolve the dependency from submodule B without a "mvn install"? (I don't wanna do this on my ci server. I fear it could be dangerous for other jobs with the same code base.)
Update 08/20/12:
POM of root folder:
<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>
<name>Foo</name>
<groupId>foo</groupId>
<artifactId>bar</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<modules>
<module>parent</module>
</modules>
</project>
Parent POM:
<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>
<name>Foo</name>
<groupId>foo</groupId>
<artifactId>parent</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<modules>
<module>../bar-a</module>
<module>../bar-b</module>
<module>../bar-c</module>
<module>../bar-d</module>
</modules>
[...]
<reporting>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>2.5.1</version>
[...]
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>2.7.1</version>
[...]
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.9.1</version>
[...]
</plugin>
</plugins>
</reporting>
</project>
POM of B:
<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>
<parent>
<groupId>foo</groupId>
<artifactId>parent</artifactId>
<version>1.0</version>
<relativePath>../parent</relativePath>
</parent>
<name>Bar B</name>
<artifactId>bar-b</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
[...]
</project>
POM of C:
<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>
<parent>
<groupId>foo</groupId>
<artifactId>parent</artifactId>
<version>1.0</version>
<relativePath>../parent</relativePath>
</parent>
<name>Bar C</name>
<artifactId>bar-c</artifactId>
<packaging>jar</packaging>
[...]
<dependencies>
<dependency>
<groupId>foo</groupId>
<artifactId>bar-b</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
[...]
</project>
回答1:
I was facing quite the same "long time" issue.
The only way (I think) to solve it with your way of working is indeed mvn install, as you suggested it.
But the problem is indeed the way you try to have different behaviours with copying your workspace. You should instead considering that CI will build and test as often as you want (each commit or every hour), but make reporting just one time (each midnight for example). You would be able to have faster continous builds, and correct documentation and reporting by night.
This is the way we work, and it is quite sufficient. We use jenkins for that, but you could trigger it with every CI soft I think) !
@hourly : mvn clean package (or install) --> from 1 to 5 minutes to run all test on all modules
@daily : mvn clean install site --> from 15 to 35 minutes to run all test on all modules + doc + reports + PDF reports
You can also use profiles to trigger different behaviours, but this is too much sophisticated for such a basic use.
来源:https://stackoverflow.com/questions/12007005/maven-site-on-multi-module-project-could-not-resolve-dependency