我如何在Maven项目之间进行汇总

时间:2018-08-19 17:18:23

标签: java maven

我正在尝试实现以下(抽象):

/ tmp / proj1:

- src/test/java/com/aDomain/proj1/Parent.java
- src/test/resources/aResource
- pom.xml

/tmp/proj1/pom.xml:

#..
<artifactId>proj1</artifactId>
<!-- Approach 1 -->
<packaging>pom</packaging>
<modules>
  <module>../proj2</module>
</modules>
<properties>
  <aResource>${project.basedir}/src/test/resources/aResource</aResource>
</properties>
#..

/tmp/proj1/src/test/java/com.aDomain.proj1/Parent .java:

package com.aDomain.proj1;
public class Parent {
  public void fubar(){ System.out.println(System.getProperty("aResource"); } //exp: /tmp/proj1/src/test/resources/aResource
}

/ tmp / proj2:

- src/test/java/com/aDomain/proj2/Child.java
- pom.xml

/tmp/proj2/pom.xml:

#..
<!-- Approach 1 -->
<parent>
  <artifactId>proj1</artifactId>
  <groupId>#..</groupId>
  <version>#..</version>
  <relativePath>../proj1/pom.xml</relativePath>
</parent>
#..
<!-- Approach 2 -->
<dependencies>
  <dependency>
    <groupId>#..</groupId>
    <artifactId>proj1</artifactId>
    <version>#..</version>
  </dependency>
</dependencies>

src / test / java / com / aDomain / proj2 / Child.java:

package com.aDomain.proj2;
import com.aDomain.proj1;

public class Child extends Parent {}

以便新Child().fubar()打印/tmp/proj1/src/test/resources/aResource。经过大量的修补,我想我需要帮助。将proj1设置为父级会使Parent无法访问Child。将其设置为依赖项将导致Parent无法构建。相反,我希望它们相互依存,以便它们在发生某些更改时自上而下重建。

0 个答案:

没有答案