忽略Maven编译中的测试源

时间:2015-07-05 18:46:38

标签: java spring maven

我已将myven构建配置为忽略我的test目录,但我的maven构建过程编译仍在编译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 个答案:

答案 0 :(得分:2)

如果您不想持续编译测试,请删除它们。您可以随时将其从版本控制中恢复。

如果你现在不想编译测试,请使用'mvn compile'而不是mvn或'mvn -DskipTests'。

毫无疑问,有一些简单的方法来编辑Pom以执行其中任何一项操作,但鉴于您已经在使用ant-run-plugin来执行一些非标准的测试相关工作,那么当您使用它时可能已经删除并重写了测试。

即使没有,你也会受到每个维护程序员的诅咒,他们需要花30分钟来解决为什么测试没有运行......

答案 1 :(得分:0)

您不应将src文件夹添加为资源,只应添加实际资源目录(按惯例src/main/resources(或者如果src/main/java中有资源),也可以添加它