0

我有两个神器:

  • artifact-A : 包含 src/test/resources/ 中的资源
<plugins>
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <version>2.2</version>
    <executions>
      <execution>
        <goals>
          <goal>test-jar</goal>
        </goals>
      </execution>
    </executions>
  </plugin>
</plugins>
  • artifact B:使用来自 artifact A 的资源
<dependency>
  <groupId>com.xxxx.yyy</groupId>
  <artifactId>artifact-A</artifactId>
  <version>3.0-SNAPSHOT</version>
  <type>test-jar</type>
  <scope>test</scope>
</dependency>

问题是资源从未在项目工件-B 中提取。我怎样才能做到这一点 ?

4

2 回答 2

1

如果您定义这样的依赖项,则永远不会提取使用的 jar,因为它将在编译等过程中放在类路径中。这意味着要从工件-A 访问资源,您需要通过类路径访问它们。

于 2012-07-24T07:49:53.357 回答
1

在 artifact-B 中,我使用了 maven-dependency-plugin 从 test-jar 中提取资源

<plugin> 
            <groupId>org.apache.maven.plugins</groupId> 
            <artifactId>maven-dependency-plugin</artifactId> 
            <version>2.4</version> 
            <executions> 
                <execution> 
                    <id>resource-dependencies</id> 
                    <phase>process-test-resources</phase> 
                    <goals> 
                        <goal>unpack-dependencies</goal> 
                    </goals> 
                    <configuration> 
                        <includeArtifactIds>artifact-A</includeArtifactIds> 
                        <includes>**/db-test/*</includes>  
                        <outputDirectory>${project.build.testOutputDirectory}</outputDirectory> 
                    </configuration> 
                </execution> 
            </executions> 
        </plugin> 
于 2012-07-24T08:13:58.850 回答