Maven : error: generics are not supported in -source 1.3 , I am using 1.6

前端 未结 5 611
礼貌的吻别
礼貌的吻别 2020-12-03 10:13

I have imported an existing Maven project into Eclipse IDE . I have modified some code in it , it compiled successfully , I am using Java 1.6 as compiler and when i am try

相关标签:
5条回答
  • 2020-12-03 10:22

    Configuring the Maven Compiler Plugin will fix the problem. It turns out the problem was caused by the Maven3 package in the Ubuntu repository. An alternate fix is to download Maven 3 from the Apache website which uses a more up to date Compiler plugin.

    I wanted to know why this was happening when the documentation states the default Java source is 1.5. To see what mvn is using for your compiler plugin use:

    mvn help:effective-pom
    

    My Maven Compiler Plugin was 2.0.2 even though I was using Maven 3.0.4 from the Ubuntu packages. When I run the same command using Maven 3.0.4 from Apache I have a plugin version 2.3.2, which defaults to Java 1.5 as expected.

    0 讨论(0)
  • 2020-12-03 10:26

    Another way that doesn't involve modifying the pom is to specify the source and target in the command line:

    mvn clean install -Dmaven.compiler.source=1.6 -Dmaven.compiler.target=1.6
    

    Note that this should be avoided generally as the build cannot be guaranteed to be repeatable this way.

    0 讨论(0)
  • 2020-12-03 10:28

    Did you declare that you want to use java 1.6 in your project pom.xml?:

    <build>
            <pluginManagement>
                <plugins>
                    <plugin>
                        <artifactId>maven-compiler-plugin</artifactId>
                        <version>2.3.2</version>
                        <configuration>
                            <source>1.6</source>
                            <target>1.6</target>
                            <compilerArgument></compilerArgument>
                        </configuration>
                    </plugin>
                </plugins>
            </pluginManagement>
        </build>
    
    0 讨论(0)
  • 2020-12-03 10:33

    I'd prefer this:

    <properties>
        <maven.compiler.source>1.5</maven.compiler.source>
        <maven.compiler.target>1.5</maven.compiler.target>
        ...
    
    0 讨论(0)
  • 2020-12-03 10:42

    You have to configure the Maven Compiler Plugin.

    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-compiler-plugin</artifactId>
      <version>2.3</version>
      <configuration>
        <source>1.6</source>
        <target>1.6</target>
      </configuration>
    </plugin>
    
    0 讨论(0)
提交回复
热议问题