开发者

Use the eclipse compiler in a maven component

I am working on a fairly big Maven project, and develop in Java with Eclipse.

To save compilation time, I would like Maven and Eclipse to share the same target, which I managed to do. However when I compile with Maven, Eclipse lacks some stuff that it puts in the bytecode, so it recompiles everything (from what I understand). I am talking about the "build automatically" feature here, so it is not Eclipse delegating the build to Maven.

To solve this, I thought I would ask Maven to use the same compiler as Eclipse. After some search on the web, I found out I could add this in the top pom:

<build>
...
<plugins>
...
<plugin>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-compiler-plugin</artifactId>
   <configuration>
           <compilerId>eclipse</compilerId>
           <source>1.5</source>
           <target>1.5</target>
           <optimize>true</optimize>
   </configuration>
   <dependencies>
           <dependency>
                   <groupId>org.codehaus.plexus</groupId>
                   <artifactId>plexus-compiler-eclipse</artifactId>
                   <version>1.8.1</version>
           </dependency>
   </dependencies>
</plugin>
</plugins>
</build>

This seems to work, but the build fails fairly quickly with lots of errors, while it succeeds with javac. I'm not sure why, but it seems that there is some conflicts linked to the fact the failing Java files are generated files.

So I thought I could try to use the Eclipse compiler only for the component I am working on (which does not have that kind of generated files). I added the above snippet in the pom of my component, but when the build reaches my component, the following error is raised:

No such compiler 'eclipse'

I also 开发者_JAVA百科tried to add the plexus-compiler-eclipse dependency in the dependencies listed in the top pom, but same error.

Do you know if what I am trying to do is possible? Any hint of how I can do it?


This is an old open issue related to maven multimodule projects: http://jira.codehaus.org/browse/MCOMPILER-165


I would guess that your issues arise from the eclipse project and maven pom not being in synch. I would suggest that you use the m2eclipse plugin to keep maven and eclipse in synch. This will configure your eclipse project by using the POM as the 'master' configuration.

I don't think you need to specifically configure what compiler to use, but you should configure the maven-compiler-plugin as you are already doing.


Make sure you use the latest version of the maven-compiler-plugin (2.3.2 right now, see this page - it's "Full name" or the little version info in the top right corner).

Apart from this, the configuration should work. You can try with the latest 1.8.4 version of the plexus-compiler-eclipse, too.

Apart from that, you need to understand that Maven has several types of dependencies. In your case, two are interesting: Build-time and plugin dependencies.

The former are collected in the dependencies element while the latter must be in a pluginManagement element. Adding a plugin to the build time classpath will not have the effect you want.


I'm not 100% sure what you are trying to achieve here but it sounds like a bad idea. Firstly, you should have Eclipse configured to being use a SDK on your system and Maven should be using the same thing. So I don't understand why you think Eclipse is adding something to the byte code which Maven would not be given they are both using the same compiler anyway.

Secondly I would not be trying to use any Eclipse components in a maven build. They are design to work within the Eclipse IDE so getting them working outside of that is usually fraught with problems. I've seen it done, but it was a hack and didn't produce very good results.

Thridly if you are having performance problems with a Maven build (not uncommon), there are a few things you can do. Firstly break down the build and work out where the time is going. My experience is that usually it's not the compilation that is the problem. Here's a list of things that I've seen slow down builds:

  • Poor quality tests. Usually slow to start up integration tests compounded with tests that are actually unit tests being run as integrations.

  • Cobertura. Great tool but because of the way Maven works, the Cobertura plugin has to run all the phases from resources to compilation again. I once shaved 40% off the during of a long Maven build by writing a plugin to stop tests being run until they where being run by the cobertura phase.

  • Over building. ie. including submodules that basically never change. Better choice is to create a profile that includes these sub mobules only when necessary or break then out to a completely seperate build.

  • Long integration testing. If the integration tests take a long time, consider putting them into a different profile and a different build on the CI server. Then your main build can go faster allowing developers to get back to work sooner, whilst the integration tests can run less often.

  • Finally - admit that Maven is a performance hog and move to something faster. Ant is probably still the fastest but a pain to setup because you have to manually configure everything. I'd suggest trialing Grandle as it fixes a lot of the issues that both Ant and Maven have. Although to be honest, I have not personally done any performance testing on it. But it does give you a level of control that Maven does not.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜