전적으로 maven이 관리하는 junit/integration 테스트로 구성된 자바 프로젝트가 있습니다. 의존성 중 하나는 zip 아카이브이며 테스트의 실행시 classpath에서 사용할 수있는 컨텐츠입니다. maven does not put the content of a zip dependency on the classpath 이래로 내가 해킹 된 해결 방법으로 생각한 것을 생각해 내야했습니다. zip 아카이브를 임시 디렉토리에 압축을 풀고 결과 디렉토리 중 하나를 /test-classes
폴더로 복사합니다. 또한 clean
단계에서 임시 디렉토리를 삭제해야했습니다. 여기에 치어의 관련 부분은 다음과 같습니다자바 테스트를위한 클래스 패스에 maven zip 의존성을 두는 법
<groupId>com.my.package</groupId>
<artifactId>test-project</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>My Test Project</name>
<properties>
<config.artifactId>environment-dev</config.artifactId>
<config.version>2.0.8-SNAPSHOT</config.version>
<tempDir>${project.basedir}/temp</tempDir>
</properties>
<build>
<plugins>
...
<!-- clean out our custom temp directory as well as the default dir during clean phase-->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.3</version>
<configuration>
<filesets>
<fileset>
<directory>${tempDir}</directory>
</fileset>
</filesets>
</configuration>
</plugin>
<!-- since the config dependency is a zip it does not get added to the classpath. So we extract
it to a temp dir, then copy the content we need into a directory on the classpath -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.8</version>
<executions>
<execution>
<id>unpack-config</id>
<phase>compile</phase>
<goals><goal>unpack-dependencies</goal></goals>
<configuration>
<includeGroupIds>com.my.package.config</includeGroupIds>
<includeArtifactIds>${config.artifactId}</includeArtifactIds>
<includeClassifiers>config</includeClassifiers>
<outputDirectory>${tempDir}</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<!-- copy the content of the zip file that we extracted into a directory on the classpath -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<phase>compile</phase>
<goals><goal>copy-resources</goal></goals>
<configuration>
<outputDirectory>${project.build.directory}/test-classes/TargetDir</outputDirectory>
<resources>
<resource>
<directory>${tempDir}/${config.artifactId}-${config.version}/TargetDir</directory>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
...
<dependency>
<groupId>com.my.package.config</groupId>
<artifactId>${config.artifactId}</artifactId>
<version>${config.version}</version>
<classifier>config</classifier>
<type>zip</type>
</dependency>
</dependencies>
이 일을 더 나은 방법이 있어야합니다.
maven이 zip 파일을 jar 파일로 취급하도록 강제 할 수 있습니까? 필자가 제공 한 링크에는이 기능이 한 번 가능했을 것이라는 암시가 있지만 설명서에는 관련이 없습니다. 이것은 할 수있는 그런 간단한 것 같이 보인다, 나는 진짜로 나가 구성 매개 변수를 어딘가에 놓쳤다는 것을 진짜로 희망한다. 누구든지 클래스 패스에 우편 종속성의 컨텐츠를 가져 오는 더 좋은 방법을 제안 할 수 있습니까?
https://issues.apache.org/jira/browse/MNG-5567 –
@ Michael-O Awesome! 감사합니다. 큰 차이를 만들 것입니다. –