忽略Maven编译中的测试源代码

3

我已经配置了我的Maven构建项目,让它忽略我的test目录,但是我的Maven构建过程中的compile仍然在编译test目录的源代码:

 [INFO] --- maven-resources-plugin:2.5:resources (default-resources) @   WEBSITE-frontend ---
 [debug] execute contextualize
 [INFO] Using 'UTF-8' encoding to copy filtered resources.
 [INFO] Copying 17411 resources
 [INFO] 
 [INFO] --- maven-compiler-plugin:3.0:compile (default-compile) @ WEBSITE-  frontend ---
 [INFO] Changes detected - recompiling the module!
 [INFO] Compiling 16 source files to C:\Users\XXXX XXXXX\git\WEBSITE\WEBSITE-web\web_web\target\classes
 [WARNING] bootstrap class path not set in conjunction with -source 1.6
 [WARNING] /C:/Users/XXXX XXXXX/git/WEBSITE/WEBSITE- web/web_web/src/main/java/com/WEBSITE/site/controllers/CurrencyController.java:   [34,41] found raw type: java.util.ArrayList
 missing type arguments for generic class java.util.ArrayList<E>
 [WARNING] /C:/Users/XXXX XXXXX/git/WEBSITE/WEBSITE-web/web_web/src/main/java/com/WEBSITE/site/controllers/CurrencyController.java: [36,24] found raw type: java.util.ArrayList
 missing type arguments for generic class java.util.ArrayList<E>
  [WARNING] /C:/Users/XXXX XXXXX/git/WEBSITE/WEBSITE-web/web_web/src/main/java/com/WEBSITE/site/overrides/QRCodeServletContext.java:[21,31] redundant cast to java.lang.String
 [INFO] 
 [INFO] --- maven-resources-plugin:2.5:testResources (default-testResources)  @ WEBSITE-frontend ---
 [debug] execute contextualize
 [INFO] Using 'UTF-8' encoding to copy filtered resources.
 [INFO] Copying 1 resource
 [INFO] 
 [INFO] --- maven-compiler-plugin:3.0:testCompile (default-testCompile) @ WEBSITE-frontend ---
 [INFO] Changes detected - recompiling the module!
 [INFO] Compiling 2 source files to C:\Users\XXXX XXXXX\git\WEBSITE\WEBSITE-web\web_web\target\test-classes
 [INFO] -------------------------------------------------------------
 [WARNING] COMPILATION WARNING : 
 [INFO] -------------------------------------------------------------
 [WARNING] bootstrap class path not set in conjunction with -source 1.6
 [INFO] 1 warning
 [INFO] -------------------------------------------------------------
 [INFO] -------------------------------------------------------------
 [ERROR] COMPILATION ERROR : 
 [INFO] -------------------------------------------------------------
 [ERROR] /C:/Users/XXXX XXXXX/git/WEBSITE/WEBSITE-web/web_web/src/test/java/com/WEBSITE/site/integration/RegistrationControllerIntegrationTest.java:[5,41] package com.fatboyindustrial.gsonjodatime does not exist
 [ERROR] /C:/Users/XXXX XXXXX/git/WEBSITE/WEBSITE-web/web_web/src/test/java/com/WEBSITE/site/integration/RegistrationControllerIntegrationTest.java:[6,23] package com.google.gson does not exist
 [ERROR] /C:/Users/XXXX XXXXX/git/WEBSITE/WEBSITE-web/web_web/src/test/java/com/WEBSITE/site/integration/RegistrationControllerIntegrationTest.java:[7,23] package com.google.gson does not exist

这是我的POM.xml文件:

 <profile>
        <id>qa</id>
        <build>
            <resources>
                <resource>
                    <directory>src</directory>
                    <excludes>
                        <exclude>test/**</exclude>
                    </excludes>
                </resource>
            </resources>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-antrun-plugin</artifactId>
                    <version>1.1</version>
                    <executions>
                        <execution>
                            <id>echo</id>
                            <phase>test</phase>
                            <goals>
                                <goal>run</goal>
                            </goals>
                            <configuration>
                                <tasks>
                                    <echo>Using QA environment</echo>
                                </tasks>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <groupId>com.github.eirslett</groupId>
                    <artifactId>frontend-maven-plugin</artifactId>
                    <version>0.0.20</version>
                    <configuration>
                        <workingDirectory>src/main/webapp/resources/js</workingDirectory>
                    </configuration>
                    <executions>
                        <execution>
                            <id>install node and npm</id>
                            <phase>generate-resources</phase>
                            <goals>
                                <goal>install-node-and-npm</goal>
                            </goals>
                            <configuration>
                                <nodeVersion>v0.12.2</nodeVersion>
                                <npmVersion>1.4.6</npmVersion>
                            </configuration>
                        </execution>
                        <execution>
                            <id>npm install</id>
                            <goals>
                                <goal>npm</goal>
                            </goals>
                            <configuration>
                                <arguments>install --production</arguments>
                            </configuration>
                        </execution>
                        <execution>
                            <id>bower install</id>
                            <goals>
                                <goal>bower</goal>
                            </goals>
                            <configuration>
                                <arguments>install --production</arguments>
                            </configuration>
                        </execution>
                        <execution>
                            <id>grunt build</id>
                            <goals>
                                <goal>grunt</goal>
                            </goals>
                            <phase>generate-resources</phase>
                            <configuration>
                                <arguments>qa</arguments>
                                <srcdir>src/main/webapp/resources/js</srcdir>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-war-plugin</artifactId>
                    <version>2.5</version>
                    <configuration>
                        <warSourceExcludes>**/node/,**/node_modules/, **/AdminLTE-master.zip, **/template_46918_iGoLso5E7rLw7cZ6WGfG.zip</warSourceExcludes>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.0</version>
                    <configuration>
                        <source>1.6</source>
                        <target>1.6</target>
                        <compilerArgument>-Xlint:all</compilerArgument>
                        <showWarnings>true</showWarnings>
                        <showDeprecation>true</showDeprecation>
                        <excludes>
                            <exclude>src/test/**</exclude>
                            <exclude>target/test-classes/**</exclude>
                        </excludes>
                        <testExcludes>
                            <testExclude>src/test/**</testExclude>
                            <testExclude>target/test-classes/**</testExclude>
                        </testExcludes>
                    </configuration>
                </plugin>
            </plugins>
            <plugins>
        <plugin>
            <artifactId>maven-eclipse-plugin</artifactId>
            <version>2.9</version>
            <configuration>
                <additionalProjectnatures>
                    <projectnature>org.springframework.ide.eclipse.core.springnature</projectnature>
                </additionalProjectnatures>
                <additionalBuildcommands>
                    <buildcommand>org.springframework.ide.eclipse.core.springbuilder</buildcommand>
                </additionalBuildcommands>
                <downloadSources>true</downloadSources>
                <downloadJavadocs>true</downloadJavadocs>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>2.3</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals><goal>copy</goal></goals>
                    <configuration>
                        <artifactItems>
                            <artifactItem>
                                <groupId>org.mortbay.jetty</groupId>
                                <artifactId>jetty-runner</artifactId>
                                <version>7.4.5.v20110725</version>
                                <destFileName>jetty-runner.jar</destFileName>
                            </artifactItem>
                        </artifactItems>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>2.4</version>
        </plugin>
       </build>
    </profile>
2个回答

2
如果您不想一直编译测试,则删除它们。您可以随时从版本控制中恢复它们。
如果您只是暂时不想编译测试,请使用'mvn compile'而不是'mvn',或者'mvn -DskipTests'。
编辑Pom文件以执行上述任何操作似乎都很简单,但由于您已经使用ant-run-plugin执行一些非标准的与测试相关的工作,因此在您使其正常工作之前,您可能已经删除并重写了测试。
即使没有这样做,每个维护程序员也会被诅咒,因为他们必须花费30分钟来弄清楚为什么测试没有运行...

1
mvn -DskipTests 也可以正常工作,而且更容易记忆和输入。 - Alexander

0
你不应该将你的 src 文件夹添加为资源,只需添加你实际的资源目录,按照惯例是 src/main/resources(如果你在 src/main/java 中有资源,请也添加进去)。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接