简体   繁体   中英

Maven: Cannot Find Symbol

I am attempting to run Maven builds of a Java project, however tests are failing stating that the Player symbol cannot be founded, despite being imported.

Maven builds are failing as follows:

[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

My config is as follows:

<?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

In your Maven-compiler-plugin definition:

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

Do not include the src folder directly. It will mess up the compilation order, Maven ends up building the test folder first, then fails on missing the main classes. Change it to this to make it work:

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

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM