在maven构建中使用Eclipse Java Compiler(ecj) [英] Using Eclipse Java Compiler (ecj) in maven builds
问题描述
所以我想使用Eclipse ECJ编译器与我的maven构建,如果我计划调试程序。一个方便的方式就是ecj配置文件:
-
编译版本
$ mvn package
-
编译快照与启用热代码替换
$ mvn -P ecj包
此外,配置文件激活可以在 settings.xml
甚至Eclipse项目属性。
我的问题是:
- 这是
- 如何配置?
- 可以使用maven工具链吗?
可以更改 javac 编译器://maven.apache.org/plugins/maven-compiler-plugin/rel =nofollow noreferrer> maven-compi LER-插件
。 Eclipse编译器捆绑在工件中 plexus-编译器eclipse
,它通过将 eclipse
设置为 compilerId
属性的/plugins/maven-compiler-plugin/compile-mojo.html#compilerId > maven-compiler-plugin 。
如果要为自定义配置文件,您可以进行以下配置:
< profile>
< id> ecj< / id>
< build>
< plugins>
< plugin>
< artifactId> maven-compiler-plugin< / artifactId>
< version> 3.6.0< / version>
< configuration>
< compilerId> eclipse< / compilerId>
< / configuration>
<依赖关系>
<依赖关系>
< groupId> org.codehaus.plexus< / groupId>
< artifactId> plexus-compiler-eclipse< / artifactId>
< version> 2.8.1< / version>
< / dependency>
< / dependencies>
< / plugin>
< / plugins>
< / build>
< / profile>
该插件维护在 plexus-compiler
GitHub存储库。版本2.8.1 使用JDT的3.11.1.v20150902-1521 ,尽管您可以通过在 org.eclipse.tycho:org.eclipse.jdt.core
在Plexus编译器依赖之后。
Eclipse uses it's own compiler (ECJ) to compile Java code. Debugging a program compiled with Eclipse is easier, because simple code changes can be applied instantly (by the hot code replacement).
Maven on the other hand uses (by default) oracle JDK, that generates different byte code preventing hot code replacement in a Eclipse debug session.
So I would like to use Eclipse ECJ compiler with my maven build, if I plan to debug the program. A convenient way for me would be a "ecj" profile:
Compile release
$ mvn package
Compile snapshot with enabled hot code replacement
$ mvn -P ecj package
Also the profile activation can be specified in settings.xml
or even Eclipse project properties.
My questions are:
- Is this the right way to go?
- How this can be configured?
- Can maven toolchain be used for this?
It is possible to change the default javac
compiler that is used by the maven-compiler-plugin
. The Eclipse compiler is bundled in the artifact plexus-compiler-eclipse
and it is declared by setting eclipse
to the compilerId
attribute of the maven-compiler-plugin
.
If you want to activate this change for a custom profile, you could have the following configuration:
<profile>
<id>ecj</id>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.0</version>
<configuration>
<compilerId>eclipse</compilerId>
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compiler-eclipse</artifactId>
<version>2.8.1</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</profile>
The plugin is maintained in the plexus-compiler
GitHub repository. Version 2.8.1 uses 3.11.1.v20150902-1521 of JDT, although you could use your own version by adding a dependency on org.eclipse.tycho:org.eclipse.jdt.core
after the Plexus Compiler dependency.
这篇关于在maven构建中使用Eclipse Java Compiler(ecj)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!