Unable to Build using MAVEN with ERROR - Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile

JavaMaven

Java Problem Overview


I have been trying to build a code using maven. But I am stuck with an error. The code is available on this github repo. google-play-crawler

My system configurations as shown by maven is followning:

Apache Maven 3.0.5 (r01de14724cdef164cd33c7c8c2fe155faf9602da; 2013-02-19 19:21:28+0530)
Maven home: /Users/tushar/Downloads/apache-maven-3.0.5
Java version: 1.6.0_65, vendor: Apple Inc.
Java home: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
Default locale: en_US, platform encoding: MacRoman
OS name: "mac os x", version: "10.9", arch: "x86_64", family: "mac"

Following is the Maven trace for the error:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project googleplaycrawler: Compilation failure -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project googleplaycrawler: Compilation failure
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:213)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
	at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
	at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
	at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
	at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
	at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
	at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
	at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
	at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
	at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
	at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
	at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
Caused by: org.apache.maven.plugin.compiler.CompilationFailureException: Compilation failure
	at org.apache.maven.plugin.compiler.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:862)
	at org.apache.maven.plugin.compiler.CompilerMojo.execute(CompilerMojo.java:129)
	at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
	... 19 more
[ERROR] 
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

Here is the pom.xml.

<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.akdeniz</groupId>
	<artifactId>googleplaycrawler</artifactId>
	<version>0.3</version>
	<packaging>jar</packaging>

	<name>Google Play Crawler</name>
	<url>https://github.com/Akdeniz/google-play-crawler</url>

	<description>Play with Google Play API :)</description>

	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
		<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
	</properties>

	<dependencies>
		<dependency>
			<groupId>org.apache.httpcomponents</groupId>
			<artifactId>httpclient</artifactId>
			<version>4.2.2</version>
		</dependency>
		<dependency>
			<groupId>commons-logging</groupId>
			<artifactId>commons-logging</artifactId>
			<version>1.1.1</version>
		</dependency>
		<dependency>
			<groupId>net.sourceforge.argparse4j</groupId>
			<artifactId>argparse4j</artifactId>
			<version>0.2.2</version>
		</dependency>
		<dependency>
			<groupId>org.apache.httpcomponents</groupId>
			<artifactId>httpcore</artifactId>
			<version>4.2.2</version>
		</dependency>
		<dependency>
			<groupId>org.apache.httpcomponents</groupId>
			<artifactId>httpclient-cache</artifactId>
			<version>4.2.2</version>
		</dependency>
		<dependency>
			<groupId>org.apache.httpcomponents</groupId>
			<artifactId>httpmime</artifactId>
			<version>4.2.2</version>
		</dependency>
		<dependency>
			<groupId>org.apache.mina</groupId>
			<artifactId>mina-core</artifactId>
			<version>2.0.7</version>
		</dependency>
		<dependency>
			<groupId>org.slf4j</groupId>
			<artifactId>slf4j-simple</artifactId>
			<version>1.7.2</version>
		</dependency>
		<dependency>
			<groupId>com.google.protobuf</groupId>
			<artifactId>protobuf-java</artifactId>
			<version>2.5.0</version>
		</dependency>

		<dependency>
			<groupId>org.testng</groupId>
			<artifactId>testng</artifactId>
			<version>6.1.1</version>
			<scope>test</scope>
		</dependency>

	</dependencies>

	<pluginRepositories>
		<pluginRepository>
			<id>protoc-plugin</id>
			<url>http://sergei-ivanov.github.com/maven-protoc-plugin/repo/releases/</url>
		</pluginRepository>
	</pluginRepositories>

	<build>
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>3.1</version>
				<configuration>
					<source>1.7</source>
					<target>1.7</target>
					<fork>true</fork
                    <executable>${JAVA_1_7_HOME}/bin/javac</executable>
					<encoding>UTF-8</encoding>
				</configuration>
			</plugin>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-assembly-plugin</artifactId>
				<version>2.3</version>
				<executions>
					<execution>
						<goals>
							<goal>attached</goal>
						</goals>
						<phase>package</phase>
						<configuration>
							<descriptorRefs>
								<descriptorRef>jar-with-dependencies</descriptorRef>
							</descriptorRefs>
							<archive>
								<manifest>
									<mainClass>com.akdeniz.googleplaycrawler.cli.googleplay</mainClass>
								</manifest>
							</archive>
						</configuration>
					</execution>
				</executions>
			</plugin>
			<plugin>
				<groupId>com.google.protobuf.tools</groupId>
				<artifactId>maven-protoc-plugin</artifactId>
				<version>0.3.1</version>

				<configuration>
					<protocExecutable>protoc</protocExecutable>
					<protoSourceRoot>${project.basedir}/src/main/protobuf/</protoSourceRoot>
					<languageSpecifications>
						<LanguageSpecification>
							<language>JAVA</language>
							<outputDirectory>${project.basedir}/src/main/java</outputDirectory>
						</LanguageSpecification>
					</languageSpecifications>
				</configuration>
				<executions>
					<execution>
						<goals>
							<goal>compile</goal>
						</goals>
					</execution>
				</executions>
			</plugin>
		</plugins>
	</build>
</project>

Java Solutions


Solution 1 - Java

Your Maven is reading Java version as 1.6.0_65, Where as the pom.xml says the version is 1.7.

Try installing the required verison.

If already installed check your $JAVA_HOME environment variable, it should contain the path of Java JDK 7. If you dont find it, fix your environment variable.

also remove the lines

 <fork>true</fork>
     <executable>${JAVA_1_7_HOME}/bin/javac</executable>

from the pom.xml

Solution 2 - Java

For my situation, I switched the value of "fork" to false, such as <fork>false</fork>. I do not understand why, hope someone could explain to me. Thanks in advance.

Solution 3 - Java

I was getting similar errors and eventually found just that cleaning the build folder resolved my issue.

mvn clean install

Solution 4 - Java

I had the same issue. When compared the java version mentioned in the pom.xml file is different and the JAVA_HOME env variable was pointing to different version of jdk.

Have the JAVA_HOME and pom.xml updated to the same jdk installation path

Solution 5 - Java

If JDK installed but still not working.

In Eclipse follow below steps:- Window --> Preference --> Installed JREs -->Change path of JRE to JDK(add).

Solution 6 - Java

I had he same problem even the correct JAVA-Version and JAVA_HOME variable was set. (In my case Java 11).

Switching to another Java-Vendor from AdoptOpenJDK to Corretto solved it.

You can use SDKMAN to change easily and quick between different Java-Versions and vendors. (JAVA_HOME variable will set automatically correct by SDKMAN).

Install SDKMAN by

curl -s "https://get.sdkman.io" | bash

then enter in the terminal:

source "$HOME/.sdkman/bin/sdkman-init.sh"

to ensure installation was successful:

sdk version

Install Java 7:

sdk install java 7.0.322-zulu
sdk default java 7.0.322-zulu

To check the versions, runtime and vendor:

java --version
mvn -v

Solution 7 - Java

For me, I changed C:\apps\Java\jdk1.8_162\bin\javac.exe to C:\apps\Java\jdk1.8_162\bin\javacpl.exe Since there was no executable with that name in the bin folder. That worked.

Solution 8 - Java

For me this trick worked

I have to end java task from the task manager, because it was not able to clean.

Rebuild it again and it worked.

Note: am using windows system.

enter image description here

Solution 9 - Java

I have faced a similar exception. Posting here in case it helps someone in future. My SpringBoot application was looking for properties from a application.yml file. But I copy-pasted the properties from a smiliar looking application.properties file. Please remember, format of both the files are not same.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionBabbarTusharView Question on Stackoverflow
Solution 1 - JavashshankView Answer on Stackoverflow
Solution 2 - JavaDavidView Answer on Stackoverflow
Solution 3 - JavagmbutcherView Answer on Stackoverflow
Solution 4 - JavaDineshView Answer on Stackoverflow
Solution 5 - JavabimalrajView Answer on Stackoverflow
Solution 6 - JavaKff7View Answer on Stackoverflow
Solution 7 - JavaYogView Answer on Stackoverflow
Solution 8 - JavaSawoodView Answer on Stackoverflow
Solution 9 - JavatusarView Answer on Stackoverflow