如何强制maven将我的项目打包为1.5?

Jim*_*mmy 9 java maven-2 maven-assembly-plugin

我正在尝试编译一个maven项目,源代码使用Generics和Java 1.5的其他特性,从而导致我的构建失败

在我的POM.xml我已经配置针对1.5的源和目标属性的生成配置,但是这并没有解决我的问题

我是对的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>
    <name>MyClass</name>
    <groupId>uk.co.mydomain</groupId>
    <artifactId>MyClass</artifactId>
    <version>1.0</version>

    <build>
      <finalName>MyClass</finalName>
      <plugins>
        <plugin>
          <artifactId>maven-assembly-plugin</artifactId>
          <configuration>
            <source>1.5</source>
            <target>1.5</target>
            <descriptors>
              <descriptor>src/main/resources/dist.xml</descriptor>
            </descriptors>
            <archive>
              <manifestFile>src/main/resources/META-INF/MANIFEST.MF</manifestFile>
            </archive>
          </configuration>
        </plugin>
      </plugins>
    </build>

    <repositories>
        <repository>
            <id>sun-repo-2</id>
            <url>http://download.java.net/maven/2/</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
    </repositories>
</project>
Run Code Online (Sandbox Code Playgroud)

在确定构建时的输出

generics are not supported in -1.3 (use -source 5 or higher to enable generics)
Run Code Online (Sandbox Code Playgroud)

Col*_*ert 25

您必须设置一些属性以使用java 1.5进行编译

<properties>
    <!-- maven-compiler-plugin configuration -->
    <maven.compiler.source>1.5</maven.compiler.source>
    <maven.compiler.target>1.5</maven.compiler.target>
</properties>
Run Code Online (Sandbox Code Playgroud)

  • 编译器插件使用的一些属性:http://maven.apache.org/plugins/maven-compiler-plugin/compile-mojo.html#source (7认同)

khm*_*ise 16

您为assembly-plugin配置了一些有关源/目标的信息,但是要配置您需要以正确方式配置编译器插件编译.

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-compiler-plugin</artifactId>
  <version>2.3.1</version>
  <configuration>
    <source>1.5</source>
    <target>1.5</target>
  </configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)

更新: 这应该与maven-enforcer-plugin结合使用以强制使用JDK 1.5而不是仅使用javac的source/target选项.