我在spring工具中开发了一个简单的maven项目。我在jenkins中部署了代码,并为此工作创建了一个管道。但是詹金斯未能编译。我在jenkins中正确配置了JDK。
它显示“在此环境中未提供编译器。也许您在JRE而不是JDK上运行?
无法在项目Course-api上执行目标org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile(默认编译):
<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>io.javabrains.springbootquickstart</groupId>
<artifactId>employee-api</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>java brains employee api</name>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.4.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<properties>
<java.version>1.8</java.version>
</properties>
</project>
我的詹金斯管道是
node{
def mvnHome
stage('git checkout process'){
echo 'started checkout'
git 'https://github.com/prakash9707/employee'
echo 'completed sucessfully'
}
stage('compile package'){
mvnHome = '/opt/apache-maven/bin'
sh "${mvnHome}/mvn package"
echo 'started compiling'
}
}
答案 0 :(得分:1)
尝试使用withMaven()管道Maven插件,而不是为构建显式设置maven。
withMaven(
// Maven installation declared in the Jenkins "Global Tool Configuration"
maven: 'M3',
// Maven settings.xml file defined with the Jenkins Config File Provider Plugin
// Maven settings and global settings can also be defined in Jenkins Global Tools Configuration
mavenSettingsConfig: 'my-maven-settings',
mavenLocalRepo: '.repository') {
// Run the maven build
sh "mvn clean install"
} // withMaven will discover the generated Maven artifacts, JUnit Surefire & FailSafe & FindBugs reports...
引用here
答案 1 :(得分:0)
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<fork>true</fork>
<executable>C:\Program Files\Java\jdk1.8.0_221\bin\javac.exe</executable>
</configuration>
</plugin>
添加“ maven-compiler-plugin”插件。 要么 Try to add JAVA_HOME