This is one of the most asked questions here in so... but why any answer works for me? i believe i have somehow a wrong maven structure in my project
I have a project like
basedir
|-src
|--many many many packages
|-test
|--testpackages
|-pom.xml
So my pom.xml
is in the same level as src
and test
folders and it isn't the typical structure like java/main/ java/test... it is the root of the project folder
<build>
<sourceDirectory>${basedir}/src</sourceDirectory>
<testSourceDirectory>${basedir}/test</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.0.1</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<excludes>
<exclude>**/test/**</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
but when i run maven install and open the generated jar the folder test is in there... how can i solve and make it ignore this folder?
Add -DskipTests
to mvn
command as a workaround. For instance:
mvn package -DskipTests
Yes, I believe your maven project structure is not correct. Maven excludes src/test/java
for packaging by default so test folder should be inside src and not in the same level as shown below:
For more details visit Maven doc
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.