问题
we are trying to build and deploy a maven artifact into our Nexus Repository Manager from Jenkins, But we are facing compilation error during the build. This is the error that we are getting.!
ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.5.1:compile (default-compile) on project studentapp: Compilation failure ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK? [ERROR] COMPILATION ERROR : [INFO] ------------------------------------------------------------- [ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
This is our pom.xml file.
<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.jdevs</groupId>
<artifactId>studentapp</artifactId>
<version>2.5-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
</plugin>
</plugins>
</build>
<distributionManagement>
<repository>
<id>deployment</id>
<name>Internal Releases</name>
<url>http://rig.eastus.cloudapp.azure.com:8081/repository/maven-releases/</url>
</repository>
<snapshotRepository>
<id>deployment</id>
<name>Internal Snapshot Releases</name>
<url>http://rig.eastus.cloudapp.azure.com:8081/repository/maven-snapshots/</url>
</snapshotRepository>
</distributionManagement>
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<type>maven-plugin</type>
</dependency>
<dependency>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
<version>3.1</version>
</dependency>
<dependency>
<groupId>org.apache.jackrabbit</groupId>
<artifactId>jackrabbit-webdav</artifactId>
<version>1.5.0</version>
</dependency>
<dependency>
<groupId>org.sonatype.sisu</groupId>
<artifactId>sisu-guice</artifactId>
<version>2.1.7</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
</dependency>
<dependency>
<groupId>aopalliance</groupId>
<artifactId>aopalliance</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>3.5.0</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact</artifactId>
<version>3.5.0</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>3.5.1</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
回答1:
Reconfigure your Jenkins . From home page goto Manage Plugins and then goto Global Tool Configuration. Reintialize JAVA_HOME field with the correct path to JDK folder.
回答2:
you need to have JDK install paths defined in your Jenkins configuration. Also if you are using master slave configuration you need to make sure that the particular has the same JDK installed (on the same location) as defined in Jenkins configuration. Same goes for ANT and Maven installations also.
回答3:
At least two other sources indicate that, with remote agents, you need to create an environment variable in the node configuration for java.home
pointing to the JAVA_HOME directory (not simply %JAVA_HOME%
or similar).
Navigate to: Jenkins > Manage Jenkins > Manage Nodes
and click the configure icon next to your remote Node. From there, scroll down to Node Properties, tick the box for Environment Variables
and define java.home
for name and the path to your JDK for the value, e.g. c:\Program Files\Java\jdk1.8.0_181
This was what I eventually needed to do, even after all system environment variables were found to be correct on the build agent server and both java -version
and javac -version
were correctly reporting.
I realize the OP doesn't specify Master or Remote, but hopefully this is helpful to someone who stumbles upon this Q & A.
This source provided the first clue but no explanation: https://www.pgs-soft.com/blog/oops-jenkins-slave-maven-not-working/
I'm unable to track down the other mention of this fix I found while googling.
来源:https://stackoverflow.com/questions/48536516/compilation-error-in-building-maven-project