【问题标题】:Compilation failure : cannot find symbol. While running Java code from CI jenkins编译失败:找不到符号。从 CI jenkins 运行 Java 代码时
【发布时间】:2018-03-20 08:33:18
【问题描述】:

我已经在互联网上徘徊了几天来寻找解决方案。我已经尝试了所有可能的解决方案,但还没有运气。问题看起来很简单,但我无法解决它。 尽管代码在 Eclipse 中编译并运行得非常好,但在运行 CI 作业 (Jenkins) 时会出错。请参阅下面的错误。

Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.0:testCompile (default-testCompile) on project clctnnotificationservFunctionalTests: Compilation failure: Compilation failure:
01:16:35 [ERROR] /clctnnotificationserv-ci-2959/workspace/clctnnotificationserv-ci-2959/clctnnotificationservFunctionalTests/src/test/java/com/paypal/collections/decision/tests/NotificationTest.java:[117,9] error: cannot find symbol

有问题的说法是:

user = PayPalAccountCreator.createUser(data);

我正在尝试调用源文件夹“src/test/java”中的静态方法 createUser(),但使用不同的包(注意:此方法之前存在于不同的源文件夹“src/main/java”中,后来由于这个问题将它移到了相同的源文件夹但它没有解决它。

这是我的 pom.xml

<dependencies>

    <!-- Add exclusion to all in the below dependency to avoid SSLPeerAuthentication issue 
    when running rbo tests using RBOTestFramework -->

    <dependency>
    <groupId>com.paypal.test.qi.jaws</groupId>
    <artifactId>Jaws</artifactId>
    <version>${jawsUserVersion}</version>
    </dependency>

    <dependency>
        <groupId>xmlunit</groupId>
        <artifactId>xmlunit</artifactId>
        <version>1.4</version>
    </dependency>


    <dependency>
        <groupId>com.paypal.test.qi.jaws</groupId>
        <artifactId>jaws-restclients</artifactId>
        <version>${jawsUserVersion}</version>
    </dependency>

    <dependency>
        <groupId>com.paypal.test.qi.jaws</groupId>
        <artifactId>jaws-raptorinfra-provider</artifactId>
        <version>${jawsUserVersion}</version>
    </dependency>

    <dependency>
        <groupId>com.paypal.test.services</groupId>
        <artifactId>restclienttestng</artifactId>
        <version>1.1.3-SNAPSHOT</version>
    </dependency>

    <dependency>
        <groupId>com.paypal.test</groupId>
        <artifactId>RiskTestUtilities</artifactId>
        <version>0.0.20</version>
        <exclusions>
            <exclusion>
                <artifactId>Bluefin-GUI</artifactId>
                <groupId>com.paypal.test.bluefin</groupId>
            </exclusion>
            <exclusion>
                <artifactId>Jaws</artifactId>
                <groupId>com.paypal.test</groupId>
            </exclusion>
            <exclusion>
                <artifactId>jaws-asfclient-deps</artifactId>
                <groupId>com.paypal.test</groupId>
            </exclusion>
        </exclusions>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
                <suiteXmlFiles>
                    <suiteXmlFile>${suiteXmlFile}</suiteXmlFile>
                </suiteXmlFiles>
            </configuration>

        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.0</version>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
            </configuration>
        </plugin>

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>cobertura-maven-plugin</artifactId>
            <inherited>false</inherited>
            <configuration>
                <skip>true</skip>
            </configuration>
        </plugin>

    </plugins>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.eclipse.m2e</groupId>
                <artifactId>lifecycle-mapping</artifactId>
                <version>1.0.0</version>
                <configuration>
                    <lifecycleMappingMetadata>
                        <pluginExecutions>
                            <pluginExecution>
                                <pluginExecutionFilter>
                                    <groupId>
                                        com.ebay.raptor.build
                                    </groupId>
                                    <artifactId>
                                        build-info-maven-plugin
                                    </artifactId>
                                    <versionRange>
                                        [1.2.0-RELEASE,)
                                    </versionRange>
                                    <goals>
                                        <goal>addscminfo</goal>
                                    </goals>
                                </pluginExecutionFilter>
                                <action>
                                    <ignore>true</ignore>
                                </action>
                            </pluginExecution>
                        </pluginExecutions>
                    </lifecycleMappingMetadata>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>
</build>

构建步骤:

【问题讨论】:

  • 如果您分享您的构建步骤将会很有帮助。
  • @pat 我已编辑问题以包含构建步骤
  • 您能否在 Eclipse 之外构建您的项目?如果您能够从终端或命令行从头开始构建项目,那么将 Jenkins 投入使用就很容易。

标签: java maven jenkins compilation maven-plugin


【解决方案1】:

终于找到了解决办法。 这是由于在 src/main/java 文件夹中定义但在 src/test/java 中使用的变量所致。 一旦我将变量移动到 src/test/java,一切都很好。我猜这可能是因为 java 在 src/main/java 之前编译 src/test/java。由于变量存在于不同的源文件夹中,因此无法找到它,因此出现错误“找不到符号”。如果我的理解有误,请指正。

【讨论】:

    猜你喜欢
    • 2020-06-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-09
    • 1970-01-01
    • 2012-07-18
    相关资源
    最近更新 更多