【问题标题】:maven compilation failure on jenkins while release:perform发布时詹金斯上的Maven编译失败:执行
【发布时间】:2018-01-23 18:26:17
【问题描述】:

我在 Jenkins 上有一份工作,我想向 Nexus 发布一个工件。它在执行期间抱怨 mavne-compiler-plugin 和 maven-release-plugin。关于问题是什么以及如何解决它的任何想法?

在 Jenkins 工作中,我还检查了 Delete workspace before build starts 并添加了 Check out to specific local branch 设置为 'master'

这是maven命令

mvn release:clean release:prepare release:perform -DreleaseVersion=${releaseVersion} -DdevelopmentVersion=${developmentVersion} -X

错误看起来像这样

[INFO] [INFO] -------------------------------------------------------------
[INFO] [ERROR] COMPILATION ERROR : 
[INFO] [INFO] -------------------------------------------------------------
[INFO] [ERROR] /var/lib/jenkins/workspace/Release-to-Nexus/target/checkout/src/main/java/com/company/security/jwt/JWTFilter.java:[19,8] cannot access javax.servlet.Filter
[INFO]   class file for javax.servlet.Filter not found
...
...
...
[INFO] [INFO] BUILD FAILURE
[INFO] [INFO] ------------------------------------------------------------------------
[INFO] [INFO] Total time: 5.919 s
[INFO] [INFO] Finished at: 2018-01-23T17:31:40+00:00
[INFO] [INFO] Final Memory: 41M/361M
[INFO] [INFO] ------------------------------------------------------------------------
[INFO] [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile (default-compile) on project testrepo: Compilation failure: Compilation failure:
[INFO] [ERROR] /var/lib/jenkins/workspace/Release-to-Nexus/target/checkout/src/main/java/com/company/security/jwt/JWTFilter.java:[19,8] cannot access javax.servlet.Filter
[INFO] [ERROR] class file for javax.servlet.Filter not found
...
...
...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 02:16 min
[INFO] Finished at: 2018-01-23T17:31:41+00:00
[INFO] Final Memory: 15M/217M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-release-plugin:2.5.3:perform (default-cli) on project testrepo: Maven execution failed, exit code: '1' -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-release-plugin:2.5.3:perform (default-cli) on project testrepo: Maven execution failed, exit code: '1'

来自 pom.xml

...
<plugin>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-compiler-plugin</artifactId>
   <version>${maven-compiler-plugin.version}</version>
   <configuration>
      <source>1.8</source>
      <target>1.8</target>    
   </configuration>
</plugin>
...
<plugin>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-release-plugin</artifactId>
   <version>2.5.3</version>
   <configuration>
      <tagNameFormat>v@{project.version}</tagNameFormat>
      <autoVersionSubmodules>true</autoVersionSubmodules>
      <releaseProfiles>releases</releaseProfiles>
   </configuration>
</plugin>
...
       <profile>
            <id>releases</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.sonatype.plugins</groupId>
                        <artifactId>nexus-staging-maven-plugin</artifactId>
                        <version>1.5.1</version>
                        <executions>
                            <execution>
                                <id>default-deploy</id>
                                <phase>deploy</phase>
                                <goals>
                                    <goal>deploy</goal>
                                </goals>
                            </execution>
                        </executions>
                        <configuration>
                            <serverId>nexus-releases</serverId>
                            <nexusUrl>https://nexus.url/</nexusUrl>
                            <skipStaging>true</skipStaging>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>

java -version

openjdk version "1.8.0_151"
OpenJDK Runtime Environment (build 1.8.0_151-8u151-b12-0ubuntu0.16.04.2-b12)
OpenJDK 64-Bit Server VM (build 25.151-b12, mixed mode)

javac -version

javac 1.8.0_151

mvn -version

Java version: 1.8.0_151, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-8-openjdk-amd64/jre
Default locale: en_US, platform encoding: ANSI_X3.4-1968
OS name: "linux", version: "4.4.0-109-generic", arch: "amd64", family: "unix"

lsb_release -a

Distributor ID: Ubuntu
Description:    Ubuntu 16.04.3 LTS
Release:    16.04
Codename:   xenial

【问题讨论】:

    标签: java maven jenkins nexus3


    【解决方案1】:

    该错误是由 maven-compiler-plugin 引发的,因此它与 编译 有关。实际上,该错误是由于代码中的“未找到符号”而导致的简单编译错误。

    您应该将此依赖项添加到您的 pom:

    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>3.0.1</version>
    </dependency>
    

    对于这个特定的库,最好也使用scope=provided 进行设置。

    【讨论】:

      猜你喜欢
      • 2021-08-19
      • 2020-08-01
      • 2017-01-29
      • 1970-01-01
      • 2015-03-19
      • 2018-05-13
      • 1970-01-01
      • 1970-01-01
      • 2019-06-16
      相关资源
      最近更新 更多