boop
boop

Reputation: 7788

Maven tries to compile to 1.5

I've build a small app. Now I wanted to replace my dependencies from downloaded *.jar's to Maven.

Maven apparently tries to build it with Java 5. But it shall be Java 7.

How do I tell maven to use JDK 1.7?

$ mvn clean install
// ...
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] /home/foo/bar.java:[17,37] diamond operator is not supported in -source 1.5
  (use -source 7 or higher to enable diamond operator)
[INFO] 2 errors 
[INFO] -----------------
// ...

Here is my 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.foo.bar</groupId>
    <artifactId>bar</artifactId>
    <version>1.0-SNAPSHOT</version>

    <dependencies>
        <dependency>
            <groupId>com.googlecode.htmlcompressor</groupId>
            <artifactId>htmlcompressor</artifactId>
            <version>1.4</version>
        </dependency>
        <dependency>
            <groupId>com.yahoo.platform.yui</groupId>
            <artifactId>yuicompressor</artifactId>
            <version>2.4.6</version>
        </dependency>
        <dependency>
            <groupId>org.jodd</groupId>
            <artifactId>jodd-core</artifactId>
            <version>3.6.6</version>
        </dependency>
    </dependencies>


</project>

Upvotes: 2

Views: 1136

Answers (1)

Kallja
Kallja

Reputation: 5472

You need to add the following plugin definition to your pom.xml under project/build/plugins

<project ... >
    ...
    <build>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
    ...
</project>

This will tell the maven compiler plugin to compile using Java 1.7.

Upvotes: 1

Related Questions