[英]Maven building jar of a war for another project's tests
PROJECT-A is a war. PROJECT-A是一场战争。 It has some code I want to use in the unit tests of PROJECT-B. 它具有一些我想在PROJECT-B的单元测试中使用的代码。
To do this, I think I need PROJECT-A to output a jar with it's classes. 为此,我想我需要PROJECT-A来输出带有其类的jar。 Here is an excerpt of the POM: 这是POM的摘录:
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<parent>
<groupId>au.com.name.redacted</groupId>
<artifactId>PARENT-PROJECT</artifactId>
<version>1.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>PROJECT-A</artifactId>
<packaging>war</packaging>
... snip
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>PROJECT-A-jar</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
When I run 当我跑步
cd PROJECT-A
mvn clean install
it outputs 它输出
[INFO] --- maven-jar-plugin:2.4:jar (PROJECT-A-jar) @ PROJECT-A ---
[INFO] Building jar: D:\Workspace\name\PROJECT-A\target\PROJECT-A-1.0.jar
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ PROJECT-A ---
[INFO] Installing D:\Workspace\name\PROJECT-A\target\PROJECT-A-1.0.jar to C:\Users\myusername\.m2\repository\au\com\name\PARENT-PROJECT\PROJECT-A\1.0\PROJECT-A-1.0.war
I do see 我看到了
D:\Workspace\name\PROJECT-A\target\PROJECT-A-1.0.jar
D:\Workspace\name\PROJECT-A\target\PROJECT-A-1.0.war
but I do not see the jar in in my repo - only the war. 但我看不到回购中的罐子,只有战争。
C:\Users\myusername\.m2\repository\au\com\name\PARENT-PROJECT\PROJECT-A\1.0\PROJECT-A-1.0.war
So then in PROJECT-B I am attempting to have it get PROJECT-A as a dependency.. 因此,在PROJECT-B中,我尝试将其作为PROJECT-A的依赖项。
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<parent>
<groupId>au.com.name.redacted</groupId>
<artifactId>PARENT-PROJECT</artifactId>
<version>1.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>PROJECT-B</artifactId>
<packaging>war</packaging>
... snip
<dependency>
<groupId>au.com.name.redacted</groupId>
<artifactId>PROJECT-A</artifactId>
<version>1.0</version>
<scope>test</scope>
</dependency>
And it fails with 它失败了
[ERROR] Failed to execute goal on project PROJECT-B: Could not resolve dependencies for project au.com.name.redacted:PROJECT-B:war:1.0: Failure to find au.com.name.redacted:PROJECT-A:jar:1.0 in http://repo.server.com.au:8081/artifactory/repo was cached in the local repository, resolution will not be reattempted until the update interval of repo has elapsed or updates are forced -> [Help 1]
I've used war plugin for this purpose. 我为此使用了war插件。 Maybe this will help: 也许这会有所帮助:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<attachClasses>true</attachClasses>
</configuration>
</plugin>
It generates war and jar with sources after build which will be commited to local m2 repo. 生成后,它将使用源生成战争和震撼,并将其提交给本地m2回购。 Configuration <attachClasses>true</attachClasses>
is important. 配置<attachClasses>true</attachClasses>
很重要。
In pom of project B use something like this (important part - <classifier>classes</classifier>
): 在项目B的pom中,使用类似以下内容(重要部分- <classifier>classes</classifier>
):
<dependency>
<groupId>projectA-groupid</groupId>
<artifactId>projectA-artifactId</artifactId>
<version>projectA-version</version>
<classifier>classes</classifier>
</dependency>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.