0

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

在詹金斯的工作中,我还检查Delete workspace before build starts并添加了Check out to specific local branch设置为“主人”

这是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
4

1 回答 1

0

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

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

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

对于这个特定的库,最好将其设置为scope=provided.

于 2018-01-23T19:41:14.853 回答