“mvn test”在控制台中给出了不同的错误

时间:2014-07-17 08:02:56

标签: java maven pom.xml

我一直面临着这三个错误:

  1. Users.java:[8,40]错误:找不到符号
  2. Users.java:[5,25]错误:包com.project.tests不存在
  3. 未找到侦听器类。
  4. 我去了这些行,发现第8,40行有这个错误,因为它无法找到此行的变量(符号)。对于第二个错误,我去了该行,它是import com.project.tests.Repo;

    import com.project.tests中的源文件夹src/test/javaimport com.project.live中有两个包src/main/java。因此,它可以找到import com.project.liveimport com.project.testscom.project.tests.Repo;位于包import com.project.tests中,这就是它给出错误的原因。

    < / p>

    在阅读stackoverflow.com和其他论坛上的不同帖子时,我发现可以通过将maven-compiler-plugin更新为version 3.1并将testng更新为最新版来解决前两个错误。昨天我做了两个更改并进行了测试,因此两个错误都被删除了,它开始出现#3错误。
    但是今天当我mvn test,然后是mvn clean时,它有时会出错1和2在一起,有时甚至是错误3。我不明白发生了什么。为了摆脱这种情况,我删除了.m2并使用mvn install再次获取,但没有任何更改,它仍然表现得很奇怪。
    我已粘贴pom.xml下方:

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
        http://maven.apache.org/xsd/maven-4.0.0.xsd">
    
        <modelVersion>4.0.0</modelVersion>
        <groupId>com.project.tests</groupId>
        <artifactId>project</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <packaging>jar</packaging>
        <name>project</name>
        <url>http://maven.apache.org</url>
        <build>
            <testResources>
                <testResource>
                    <directory>src/test/resource</directory>
                    <excludes>
                        <exclude>**/*.java</exclude>
                    </excludes>
                </testResource>
            </testResources>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.1</version>
                    <configuration>
                        <source>1.7</source>
                        <target>1.7</target>
                        <fork>true</fork>
                        <executable>${JAVA_HOME}/bin/javac</executable>
                        <encoding>UTF-8</encoding>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>ch.fortysix</groupId>
                    <artifactId>maven-postman-plugin</artifactId>
                    <version>0.1.6</version>
                    <executions>
                        <execution>
                            <id>send a mail</id>
                            <phase>test</phase>
                            <goals>
                                <goal>send-mail</goal>
                            </goals>
                            <inherited>false</inherited>
                            <configuration>
                                <from>
                                    myofficial@emailid.com
                                </from>
                                <subject>
                                    Test Results
                                </subject>
                                <failonerror>
                                    true
                                </failonerror>
                                <mailhost>
                                </mailhost>
                                <receivers>
                                    <receiver>myofficial2@emailid.com</receiver>
                                </receivers>
                                <htmlMessageFile>
                                    /var/lib/jenkins/jobs/Testing/workspace/target/surefire-reports/emailable-report.html
                                </htmlMessageFile>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
                <!-- Maven suerfire config -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>2.14.1</version>
                    <configuration>
                        <forkCount>0</forkCount>
                        <suiteXmlFiles>
                            <suiteXmlFile>
                                /home/ubuntu/automation/projectAutomate/Chrome.xml
                            </suiteXmlFile>
                        </suiteXmlFiles>
                        <testFailureIgnore>
                            true
                        </testFailureIgnore>
    
                        <properties>
    
                            <property>
                                <name>listener</name>
                                <value>
                                    org.uncommons.reportng.HTMLReporter,
                                    org.uncommons.reportng.JUnitXMLReporter
                                </value>
                            </property>
                        </properties>
                        <workingDirectory>target/</workingDirectory>
                    </configuration>
    
    
    
                </plugin>
    
    
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-report-plugin</artifactId>
                    <version>2.16</version>
                </plugin>
            </plugins>
        </build>
    
        <reporting>
            <plugins>
                <!-- TestNG-xslt related configuration. -->
                <plugin>
                    <groupId>org.testng.xslt</groupId>
                    <artifactId>testng-xslt-plugin</artifactId>
                    <version>1.1</version>
                    <configuration>
                        <!-- Output directory for the report -->
                        <outputDir>
                            /var/lib/jenkins/jobs/DailySignUpTests/workspace/target/testng-xslt-report/
                        </outputDir>
                        <sortTestCaseLinks>true</sortTestCaseLinks>
                        <testDetailsFilter>FAIL,SKIP,PASS,CONF,BY_CLASS</testDetailsFilter>
                        <showRuntimeTotals>true</showRuntimeTotals>
                    </configuration>
                </plugin>
    
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>2.5</version>
                    <configuration>
                        <properties>
                            <property>
                                <name>usedefaultlisteners</name>
                                <value>false</value>
                            </property>
                            <property>
                                <name>listener</name>
                                <value>
                                    org.uncommons.reportng.HTMLReporter,
                                    org.uncommons.reportng.JUnitXMLReporter
                                </value>
                            </property>
                        </properties>
                        <workingDirectory>target/</workingDirectory>
                    </configuration>
                </plugin>
            </plugins>
        </reporting>
    
        <properties>
            <project.build.sourceEncoding>
                UTF-8
            </project.build.sourceEncoding>
        </properties>
        <dependencies>
            <!-- first -->
    
    
    
            <dependency>
                <groupId>org.seleniumhq.selenium</groupId>
                <artifactId>selenium-server</artifactId>
                <version>2.34.0</version>
            </dependency>
    
    
            <dependency>
                <groupId>org.seleniumhq.selenium</groupId>
                <artifactId>selenium-java</artifactId>
                <version>2.34.0</version>
            </dependency>
    
    
            <dependency>
                <groupId>org.seleniumhq.selenium</groupId>
                <artifactId>selenium-support</artifactId>
                <version>2.34.0</version>
            </dependency>
    
            <dependency>
                <groupId>org.seleniumhq.selenium</groupId>
                <artifactId>selenium-api</artifactId>
                <version>2.34.0</version>
            </dependency>
    
    
            <dependency>
                <groupId>org.hudsonci.plugins</groupId>
                <artifactId>testng-plugin</artifactId>
                <version>0.32-h-1</version>
            </dependency>
    
            <dependency>
                <groupId>velocity</groupId>
                <artifactId>velocity</artifactId>
                <version>1.4</version>
                <scope>test</scope>
            </dependency>
    
            <dependency>
                <groupId>org.uncommons</groupId>
                <artifactId>reportng</artifactId>
                <version>1.1.2</version>
                <scope>test</scope>
                <exclusions>
                    <exclusion>
                        <groupId>org.testng</groupId>
                        <artifactId>testng</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>
    
            <dependency>
                <groupId>com.google.inject</groupId>
                <artifactId>guice</artifactId>
                <version>3.0</version>
                <scope>test</scope>
            </dependency>
    
    
            <!-- second -->
            <dependency>
                <groupId>org.testng</groupId>
                <artifactId>testng</artifactId>
                <version>6.5.2</version>
            </dependency>
            <!-- third -->
            <dependency>
                <groupId>net.sourceforge.jexcelapi</groupId>
                <artifactId>jxl</artifactId>
                <version>2.6.12</version>
            </dependency>
            <dependency>
                <groupId>com.github.detro.ghostdriver</groupId>
                <artifactId>phantomjsdriver</artifactId>
                <version>1.0.4</version>
            </dependency>
            <dependency>
                <groupId>
    org.slf4j
              </groupId>
                <artifactId>
    nlog4j
              </artifactId>
                <version>
    1.2.25
              </version>
            </dependency>
        </dependencies>
    
        <repositories>
            <repository>
                <id>java-net</id>
                <url>http://download.java.net/maven/2</url>
            </repository>
        </repositories>
    
    </project>
    

1 个答案:

答案 0 :(得分:1)

通常的原因是您在src/main/java/下方的代码中使用了测试类。 Maven不允许这样做 - 这是有充分理由的。将所有测试代码保存在src/test/java

还要确保所有Java代码都在src/*/java; src/*/resources中的文件不被视为我的Maven代码。