Maven:找不到符号

时间:2016-01-18 16:03:08

标签: java maven

我正在尝试运行Java项目的Maven版本,但测试失败表明尽管导入了Player符号,但仍然无法创建它。

Maven构建失败如下:

[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] /var/lib/jenkins/workspace/XIVStats-Gatherer-Java/src/test/com/ffxivcensus/gatherer/PlayerTest.java:[4,31] error: cannot find symbol
[ERROR]  package com.ffxivcensus.gatherer
/var/lib/jenkins/workspace/XIVStats-Gatherer-Java/src/test/com/ffxivcensus/gatherer/PlayerTest.java:[22,8] error: cannot find symbol
[ERROR]  class PlayerTest
/var/lib/jenkins/workspace/XIVStats-Gatherer-Java/src/test/com/ffxivcensus/gatherer/PlayerTest.java:[22,27] error: cannot find symbol
[ERROR]  class PlayerTest
/var/lib/jenkins/workspace/XIVStats-Gatherer-Java/src/test/com/ffxivcensus/gatherer/PlayerTest.java:[116,12] error: cannot find symbol
[ERROR]  class PlayerTest
/var/lib/jenkins/workspace/XIVStats-Gatherer-Java/src/test/com/ffxivcensus/gatherer/PlayerTest.java:[116,28] error: cannot find symbol
[INFO] 5 errors 
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 6.415 s
[INFO] Finished at: 2016-01-18T15:35:38+01:00
[INFO] Final Memory: 18M/206M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:testCompile (default-testCompile) on project XIVStats-Gatherer-Java: Compilation failure: Compilation failure:
[ERROR] /var/lib/jenkins/workspace/XIVStats-Gatherer-Java/src/test/com/ffxivcensus/gatherer/PlayerTest.java:[4,31] error: cannot find symbol
[ERROR] package com.ffxivcensus.gatherer
[ERROR] /var/lib/jenkins/workspace/XIVStats-Gatherer-Java/src/test/com/ffxivcensus/gatherer/PlayerTest.java:[22,8] error: cannot find symbol
[ERROR] class PlayerTest
[ERROR] /var/lib/jenkins/workspace/XIVStats-Gatherer-Java/src/test/com/ffxivcensus/gatherer/PlayerTest.java:[22,27] error: cannot find symbol
[ERROR] class PlayerTest
[ERROR] /var/lib/jenkins/workspace/XIVStats-Gatherer-Java/src/test/com/ffxivcensus/gatherer/PlayerTest.java:[116,12] error: cannot find symbol
[ERROR] class PlayerTest
[ERROR] /var/lib/jenkins/workspace/XIVStats-Gatherer-Java/src/test/com/ffxivcensus/gatherer/PlayerTest.java:[116,28] error: cannot find symbol
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

我的配置如下:

<?xml version="1.0" encoding="UTF-8"?>
<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.ffxivcensus.gatherer</groupId>
    <artifactId>XIVStats-Gatherer-Java</artifactId>
    <version>1.0pre</version>
    <name>XIVStats Lodestone Gatherer</name>
    <url>https://github.com/xivstats</url>


    <licenses>
        <license>
            <name>BSD 2-Clause License</name>
            <url>https://opensource.org/licenses/BSD-2-Clause</url>
            <distribution>repo</distribution>
        </license>
    </licenses>

    <issueManagement>
        <url>https://github.com/XIVStats/XIVStats-Gatherer-Java/issues</url>
        <system>GitHub Issues</system>
    </issueManagement>

    <developers>
        <developer>
            <email>me@example.com</email>
            <name>Peter Reid</name>
            <url>https://github.com/reidweb</url>
            <id>reidweb</id>
        </developer>
        <developer>
            <email>me@example.com</email>
            <name>Jonathan Price</name>
            <url>https://github.com/pricetx</url>
            <id>pricetx</id>
        </developer>
    </developers>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <repositories>
        <repository>
            <id>mvnrepository.com</id>
            <name>mvnrepository.com</name>
            <url>http://mvnrepository.com/</url>
        </repository>
    </repositories>

    <build>
        <directory>target</directory>
        <outputDirectory>target/classes</outputDirectory>
        <finalName>${project.artifactId}-${project.version}</finalName>
        <testOutputDirectory>target/test</testOutputDirectory>
        <sourceDirectory>src/main</sourceDirectory>
        <testSourceDirectory>src/test/</testSourceDirectory>

        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <includes>
                        <include>src</include>
                    </includes>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <archive>
                        <manifest>
                            <mainClass>com.ffxivcensus.gatherer.GathererController</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>

        </plugins>

    </build>

    <dependencies>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.38</version>
        </dependency>
        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <version>9.4.1207</version>
        </dependency>
        <dependency>
            <groupId>org.jsoup</groupId>
            <artifactId>jsoup</artifactId>
            <version>1.8.3</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.10</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

</project>

See this github project

1 个答案:

答案 0 :(得分:4)

在Maven-compiler-plugin定义中:

        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.3</version>
            <configuration>
                <includes>
                    <include>src</include>
                </includes>
            </configuration>
        </plugin>

不要直接包含src文件夹。它会搞乱编译顺序,Maven最先建立测试文件夹,然后错过了主类。将其改为此以使其有效:

        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.3</version>
        </plugin>