Maven不使用Java 7 [英] Maven doesn't use Java 7

查看:97
本文介绍了Maven不使用Java 7的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想打包maven-(多)模块,父POM包括:

 <插件> 
< groupId> org.apache.maven.plugins< / groupId>
< artifactId> maven-compiler-plugin< / artifactId>
< version> 2.3.2< / version>
< configuration>
< source> $ {maven.compiler.source}< / source>
< target> $ {maven.compiler.target}< / target>
< encoding> $ {project.build.sourceEncoding}< / encoding>
< / configuration>
< / plugin>

我正在使用Java 1.7,其属性指定如下:

 < properties> 
< project.build.sourceEncoding> UTF-8< /project.build.sourceEncoding>
< maven.compiler.source> 1.7< /maven.compiler.source>
< maven.compiler.target> 1.7< /maven.compiler.target>
< slf4j.version> 1.6.1< /slf4j.version>
< / properties>

Maven版本是2.2.1:



< pre class =lang-none prettyprint-override> johannes @ luna:〜/ workspace / treetank / bundles / treetank-core $ mvn -version
Apache Maven 2.2.1(rdebian-6 )
Java版本:1.7.0
Java home:/usr/lib/jvm/jdk1.7.0/jre
默认语言环境:en_US,平台编码:UTF-8
OS名称:linux版本:3.0.0-14-genericarch:amd64系列:unix

我不知道为什么它不使用Java版本1.7。当调用 mvn package 时,我得到错误(使用-source 7或更高版本来启用菱形运算符)。你知道它为什么尝试使用1.6吗?



有效的POM是:

 < plugin> 
< artifactId> maven-compiler-plugin< / artifactId>
< version> 2.3.2< / version>
< executions>
< execution>
< id> default-testCompile< / id>
< phase> test-compile< / phase>
< goals>
< goal> testCompile< / goal>
< / goals>
< configuration>
< source> 1.7< / source>
< target> 1.7< / target>
< encoding> UTF-8< / encoding>
< / configuration>
< / execution>
< execution>
< id> default-compile< / id>
< phase> compile< / phase>
< goals>
< goal> compile< / goal>
< / goals>
< configuration>
< source> 1.7< / source>
< target> 1.7< / target>
< encoding> UTF-8< / encoding>
< / configuration>
< / execution>
< / executions>
< configuration>
< source> 1.7< / source>
< target> 1.7< / target>
< encoding> UTF-8< / encoding>
< / configuration>
< / plugin>


解决方案

这可能不适用于maven 2.2.1,但是使用Maven 3.0.4,只需将两个属性添加到pom的属性即可为我启用Java 7:

 < properties> 
< maven.compiler.source> 1.7< /maven.compiler.source>
< maven.compiler.target> 1.7< /maven.compiler.target>
< / properties>


I want to package a maven-(multi)module, the parent POM includes:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-compiler-plugin</artifactId>
  <version>2.3.2</version>
  <configuration>
    <source>${maven.compiler.source}</source>
    <target>${maven.compiler.target}</target>
    <encoding>${project.build.sourceEncoding}</encoding>
  </configuration>
</plugin>

I'm using Java 1.7 and the properties are specified as follows:

<properties>
  <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  <maven.compiler.source>1.7</maven.compiler.source>
  <maven.compiler.target>1.7</maven.compiler.target>
  <slf4j.version>1.6.1</slf4j.version>
</properties>

The Maven version is 2.2.1:

johannes@luna:~/workspace/treetank/bundles/treetank-core$ mvn -version
Apache Maven 2.2.1 (rdebian-6)
Java version: 1.7.0
Java home: /usr/lib/jvm/jdk1.7.0/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux" version: "3.0.0-14-generic" arch: "amd64" Family: "unix"

I have no clue why it doesn't use Java version 1.7. When invoking mvn package I get the error (use -source 7 or higher to enable diamond operator) for instance. Do you know why it tries using 1.6?

The effective POM is:

  <plugin>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>2.3.2</version>
    <executions>
      <execution>
        <id>default-testCompile</id>
        <phase>test-compile</phase>
        <goals>
          <goal>testCompile</goal>
        </goals>
        <configuration>
          <source>1.7</source>
          <target>1.7</target>
          <encoding>UTF-8</encoding>
        </configuration>
      </execution>
      <execution>
        <id>default-compile</id>
        <phase>compile</phase>
        <goals>
          <goal>compile</goal>
        </goals>
        <configuration>
          <source>1.7</source>
          <target>1.7</target>
          <encoding>UTF-8</encoding>
        </configuration>
      </execution>
    </executions>
    <configuration>
      <source>1.7</source>
      <target>1.7</target>
      <encoding>UTF-8</encoding>
    </configuration>
  </plugin>

解决方案

This may not work in maven 2.2.1, but with Maven 3.0.4, simply adding the two properties to the pom's properties enables Java 7 for me:

<properties>
  <maven.compiler.source>1.7</maven.compiler.source>
  <maven.compiler.target>1.7</maven.compiler.target>
</properties>

这篇关于Maven不使用Java 7的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆