Tôi đã tìm kiếm trên diễn đàn để tìm câu trả lời cho vấn đề của mình, nhưng tôi không thể tìm thấy nó. Vấn đề của tôi là:Làm thế nào để làm cho maven lấy tài nguyên từ/src/test/resources thay vì/src/main/resources cho một dự án phụ thuộc?
Tôi có hai dự án: ProjectA và ProjectB. ProjectB sử dụng ProjectA. Trong ProjectA tôi có hai thư mục: /src/main/resources và/src/test/resources. Trong ProjectB tôi chạy: mvn clean install. Tôi muốn, trong giai đoạn thử nghiệm, các lớp trong ProjectB sử dụng tài nguyên từ/src/test/resources thay vì/src/main/resources.
Đây là những gì tôi đã cố gắng: http://www.waltercedric.com/java-j2ee-mainmenu-53/361-maven-build-system/1349-maven-reusing-test-classes-across-multi-modules-projects.html
Nó tương tự như vấn đề của tôi, nhưng sau khi tôi cấu hình mục tiêu thử nghiệm jar cho PROJECTA, ProjectB vẫn chạy các bài kiểm tra trên đường, mà các lớp học trong sử dụng tài sản PROJECTA từ/src/main/resources thay vì/src/test/resources.
pom.xml của tôi trong PROJECTA trông giống như:
<project ...>
<parent>
...
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>ProjectA</artifactId>
<packaging>jar</packaging>
<dependencies>
...
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<testResources>
<testResource>
<directory>src/test/resources</directory>
<filtering>true</filtering>
</testResource>
</testResources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Trong ProjectB pom.xml của tôi trông giống như:
<project ...>
<parent>
...
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>ProjectB</artifactId>
<packaging>jar</packaging>
<build>
<plugins>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.sensano</groupId>
<artifactId>ProjectA</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>ProjectA</groupId>
<artifactId>ProjectA</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>test</scope>
<type>test-jar</type>
</dependency>
</dependencies>
</project>
Có một phương pháp Bất kỳ trợ giúp sẽ được đánh giá cao!
Trân trọng,
Mateusz Moroz