问题
I want to build the html version of my game from the command line using maven. However, when I run the package
command for the core
folder:
mvn clean package -pl core,html
I get the following errors because of some unit tests in my source path:
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /home/klenwell/projects/mygame/playn/mygame/core/src/main/java/mygame/playn/tests/unit/UserDataTest.java:[3,23] package org.junit does not exist
[ERROR] /home/klenwell/projects/mygame/playn/mygame/core/src/main/java/mygame/playn/tests/unit/UserDataTest.java:[7,16] package org.junit does not exist
...
How can I exclude the directory with these test files from being included in the compilation?
回答1:
It is not a good idea to mix source
and test
classes. As per maven convention, you should move the tests from src/main/java
to src/test/java
.
You should add the dependency for junit
so that the tests can be compiled.
You can choose to skip the tests (if they are broken) by using the -DskipTests
or similar while running maven.
回答2:
Adding the following block to the plugins
section of my core pom.xml
file excluded tests from compilation and allowed the build to succeed:
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<excludes>
<exclude>**/*Test*.java</exclude>
</excludes>
</configuration>
</plugin>
来源:https://stackoverflow.com/questions/10924298/in-playn-how-do-you-exclude-a-directory-from-being-compiled-by-maven