2015-05-30 33 views
1

我使用scala-maven-plugin使用Maven构建Scala项目。我的项目依赖于来自Java 8的一些库。我想在我的pom中指定该项目需要Java 8(使用类似于-target=jdk-1.8的东西,它似乎不存在),以便在某人遇到某人时会更优雅/尝试使用Java版本<进行编译8.目前,它只是无法找到我想要导入的包。要求Java 8使用Maven构建Scala项目

我试着用sourcetarget设定的附加maven-compiler-plugin〜1.8,因为scala-maven-plugin正在处理编译,而不是maven-compiler-plugin这并不工作,大概。

这可能吗?

+0

您是否试过这个? http://maven.apache.org/plugins/maven-compiler-plugin/examples/set-compiler-source-and-target.html – Bruno

+0

我有,它不工作,大概是因为scala-maven-plugin处理编译(我甚至没有我的原始pom中的maven-compiler-plugin)。感谢您指出这一点,我会将其添加到我的问题。 –

+0

http://davidb.github.io/scala-maven-plugin/compile-mojo.html#jvmArgs – cchantep

回答

1

在运行Maven构建时,您可以使用Maven Enforcer Plugin来强制执行一些要声明的规则。

这里您要确保Java版本的版本至少为8。您可以通过将以下内容添加到您的pom.xml文件中来实现此目的:

<build> 
    <plugins> 
    <plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-enforcer-plugin</artifactId> 
     <version>1.4</version> 
     <executions> 
     <execution> 
      <id>enforce-java</id> 
      <goals> 
      <goal>enforce</goal> 
      </goals> 
      <configuration> 
      <rules> 
       <requireJavaVersion> 
       <version>[1.8,)</version> 
       </requireJavaVersion> 
      </rules>  
      </configuration> 
     </execution> 
     </executions> 
    </plugin> 
    </plugins> 
</build>