주 리소스와 테스트 리소스 모두에 대해 하나의 모듈 (shared-resources
)에 의존하는 다중 모듈 프로젝트를 리팩터링합니다.다중 모듈 프로젝트에서 테스트 리소스를 테스트하십시오.
parent
|_ shared-resources
|_ child
현재 모듈은 maven-resource-plugin
를 사용하여 shared-resources
를 포함한다.
현재 child/pom.xml
:
...
<resources>
<resource>
<directory>../shared-resources/src/main/resources</directory>
</resource>
</resources>
<testResources>
<testResource>
<directory>../shared-resources/src/test/resources</directory>
</testResource>
</testResources>
...
나는 그들이이 shared-resources
모듈의 항아리와 테스트 항아리 포장을 통해 포함되도록 몇 가지 관련 질문 (예 : "Specify common resources in a multi-module maven project"과 "로, 종속성을 구조 조정하고 싶습니다 Share test resources between maven projects ")를 제안합니다. 새로운 shared-resources/pom.xml
: child/pom.xml
...
<build>
<plugins>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
...
새로운 :
...
<dependency>
<groupId>com.example</groupId>
<artifactId>shared-resources</artifactId>
<version>0.0.1</version>
</dependency>
<dependency>
<groupId>com.example</groupId>
<artifactId>shared-resources</artifactId>
<version>0.0.1</version>
<scope>test</scope>
<type>test-jar</type>
</dependency>
...
나는 자원의 부족 그러나 아이 테스트, 테스트를 실행
. 속성 테스트가 수행 액세스하는 위치maven clean test --projects child --also-make
maven clean install -DskipTests && mvn test --projects child
maven clean verify --projects child --also-make
내 권위있는 테스트가 mvn clean install -DskipTests -pl :child -am && mvn test -pl :child -Dtest='PropertiesAccessTest'
을하고있다 :
나는 다양한 방법으로 내 빌드를 실행했습니다
public class PropertiesAccessTest {
@Test
public void resourceAccessible() throws URISyntaxException, IOException {
propertyExists(
"abcdef=12345",
"test.properties"
);
}
private void propertyExists(String string, String fileName) throws IOException, URISyntaxException {
URL url = getClass().getClassLoader().getResource(fileName);
assertNotNull(url);
assertTrue("file should exist", new File(url.getFile()).exists());
assertTrue("file should contain property", Files.readAllLines(Paths.get(url.toURI()))
.stream().anyMatch(l -> l.contains(string)));
}
}
test.properties
은 shared-resources/src/test/resources/
입니다 (위의 구성을 이해해야하므로 포함되어야 함). 그러나 테스트는 항상 "파일이 있어야합니다."와 함께 실패합니다.
내 로컬 .m2
리포지토리에 테스트 리소스가 포함 된 테스트 jar가 예상대로 포함되어 있는지 확인할 수 있습니다.
내가 뭘 잘못하고 있니?
'공유 리소스'는 어떤 종류의 리소스입니까? 이러한 리소스가 적절한 모듈에 속한다는 인상을 받았습니까? – khmarbaise
어떤 명령을 실행합니까? 'shared-resources' 아티팩트가 제대로 설치 되었습니까?두 프로젝트 모두에 대한 전체 POM을 제공하면 도움이 될 수 있으며, 주어진 요소에서 예술을 말합니다. –
@ 피에르 B. 위의 빌드 명령을 상세히 설명했습니다. 그것이 가치있는 일이라면'share-resources' jar와 test jar의 내용이 예상 한 것과 같은지 확인할 수 있습니다. – jwilner