1

Problem

I decided to get spring boot hello word example to work with Java 1.8 but an annoying dependency issues. In the answer section I explain what solved my problem as well as some hints on how to bring everything on your machine up to date. The error I was getting was:

[ERROR] realm =    plugin>org.apache.maven.plugins:maven-compiler-plugin:3.x
[ERROR] strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
[ERROR] urls[0] = file:/Users/xxx/.m2/repository/org/apache/maven/plugins/maven-compiler-plugin/3.1/maven-compiler-plugin-3.1.jar
[ERROR] urls[1] = file:/Users/xxx/.m2/repository/org/codehaus/plexus/plexus-utils/1.5.1/plexus-utils-1.5.1.jar
[ERROR] urls[2] = file:/Users/xxx/repository/org/apache/maven/shared/maven-shared-utils/0.1/maven-shared-utils-0.1.jar
[ERROR] urls[3] = file:/Users/xxx/repository/com/google/code/findbugs/jsr305/2.0.1/jsr305-2.0.1.jar
[ERROR] urls[4] = file:/Users/xxx/.m2/repository/org/apache/maven/shared/maven-shared-incremental/1.1/maven-shared-incremental-1.1.jar
[ERROR] urls[5] = file:/Users/xxx/.m2/repository/org/codehaus/plexus/plexus-component-annotations/1.5.5/plexus-component-annotations-1.5.5.jar
[ERROR] urls[6] = file:/Users/xxx/.m2/repository/org/codehaus/plexus/plexus-compiler-api/2.2/plexus-compiler-api-2.2.jar
[ERROR] urls[7] = file:/Users/xxx/.m2/repository/org/codehaus/plexus/plexus-compiler-manager/2.2/plexus-compiler-manager-2.2.jar
[ERROR] urls[8] = file:/Users/xxx/.m2/repository/org/codehaus/plexus/plexus-compiler-javac/2.2/plexus-compiler-javac-2.2.jar
[ERROR] urls[9] = file:/Users/xxx/.m2/repository/org/apache/xbean/xbean-reflect/3.4/xbean-reflect-3.4.jar
[ERROR] urls[10] = file:/Users/xxx/.m2/repository/log4j/log4j/1.2.12/log4j-1.2.12.jar
[ERROR] urls[11] = file:/Users/xxx/.m2/repository/commons-logging/commons-logging-api/1.1/commons-logging-api-1.1.jar
[ERROR] urls[12] = file:/Users/xxx/.m2/repository/com/google/collections/google-collections/1.0/google-collections-1.0.jar
[ERROR] urls[13] = file:/Users/xxx/.m2/repository/junit/junit/3.8.2/junit-3.8.2.jar

Solutions that didn't work

A lot of the threads were suggesting removing the ~/.m2/ repositories like here but it did not solve my problem.

Some others said that this is due to the Java 1.8 and it works perfectly for them with Java 1.7! But couldn't believe them as it did not make sense. And I really wanted to get this simple example to work with Java 8.

Solution summary

It was a dependency conflict but had nothing to do with the Java version or the repositories under .m2 folder for me.

The source of the error was a dependency conflict that was caused plugin>org.apache.maven.plugins:maven-compiler-plugin:3.x.


Other related sources

Other questions on stackoverflow that are similar but didn't solve my problem with spring boot are as follows:

1- maven-build-error-failed-to-execute-goal-missing-a-class

2- failed-to-execute-goal-org-apache-maven-pluginsmaven-compiler-plugin2-3-2comp

3- maven-release-plugin-issue-failed-to-execute-goal-org-apache-maven-pluginsmav

4- maven-archetype-problem

Community
  • 1
  • 1
AmirHd
  • 10,308
  • 11
  • 41
  • 60

1 Answers1

0

Solution

As I mentioned, the source of the error was a dependency conflict that was caused plugin>org.apache.maven.plugins:maven-compiler-plugin:3.x. Based on the comment made in some cases specifying the Java version through <properties><java.version>1.8</java.version></properties> solves their problem for some (based on the guide here).

However in my case (checkout the specs) only specifying the maven compiler plugin and through the following code solved my problem:

<plugin>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>2.3.2</version>
    <configuration>
        <source>1.8</source>
        <target>1.8</target>
    </configuration>
</plugin>

Specs

  • Java 1.8_45
  • Maven 3.3.3
  • OS X Yosemite

Files

Basically I had to specify the maven-compiler-plugin in my pom.xml (see below).

POM.XML

<?xml version="1.0" encoding="UTF-8"?>
<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.mycompany</groupId>
    <artifactId>helloworld</artifactId>
    <version>0.1.0</version>
    <!-- Inherit defaults from Spring Boot -->
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.2.2.RELEASE</version>
    </parent>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

    </dependencies>
    <build>
        <plugins>

            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>

        </plugins>
    </build>
</project>

SampleContoroller.java

import org.springframework.boot.*;
import org.springframework.boot.autoconfigure.*;
import org.springframework.web.bind.annotation.*;

@RestController
@EnableAutoConfiguration
public class SampleController {

    @RequestMapping("/")
    String home() {
        return "Hello World!";
    }

    public static void main(String[] args) throws Exception {
        SpringApplication.run(SampleController.class, args);
    }
}

Project folder structure

Just follow maven standard structure.

Hint Please feel free to give me feedback in the comments if this solved your problem, or if you faced other issues.

AmirHd
  • 10,308
  • 11
  • 41
  • 60
  • 1
    Why do you even define the compiler plugin and not simply do `1.8` in your pom. That should all you need to get it working for java 8, the compiler plugin is already defined in the parent pom and you simply need to tell it what version of java to use. Basically [this guide](https://spring.io/guides/gs/spring-boot/) simply works for me no need to mess around with an additional plugin etc. – M. Deinum Jul 14 '15 at 07:33
  • Thanks heaps @M.Deinum your solution better so I updated the pom.xml. There were so many examples for different version of spring boot and java that I forgot about this example. – AmirHd Jul 14 '15 at 07:47
  • You only added the version, you should also remove the compiler plugin. How to change the java version is simply explained in the reference guide [here](http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#using-boot-maven-java-version). – M. Deinum Jul 14 '15 at 07:47
  • Yep I figured, I was in middle of it doing it! – AmirHd Jul 14 '15 at 07:49
  • To double check I ran a 'mvn clean' and ran the 'mvn spring-boot:run' and it gives me the same error mentioned above again despite of the java version specified! Can you please check @M.Deinum and let me know if this is the case for you so that I can update the answer. If possible remove your .m2 repositories to make sure we have the same starting point. – AmirHd Jul 14 '15 at 07:55
  • @M.Deinum no worries I will add both cases to make sure the answer covers my issue too. After the target is build mine is fine but it does not produce the target without specifying version 2.3.2 of maven compiler plugin. Also I am on OS X that could be another reason. – AmirHd Jul 14 '15 at 07:59
  • I'm on osx also. Followed the guide tested with every 1.2.x version works like a charm. Hence I suspect a borked java version or something like that on your system. Used JDK 1.8.25 not the most recent.. – M. Deinum Jul 14 '15 at 08:12
  • Tested with multiple version of Spring Boot and JDK 1.8 all work for me. – M. Deinum Jul 14 '15 at 09:00
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/83266/discussion-between-amirhd-and-m-deinum). – AmirHd Jul 15 '15 at 00:13