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 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?
Eclipse is one of the most popular IDEs for Java and Android application development. It provides an excellent plugin, M2Eclipse, which integrates Maven and Eclipse. M2Eclipse automatically downloads required dependencies from remote Maven repositories.
Building and Running the Maven Project in Eclipse To run the maven project, select it and go to “Run As > Java Application”. In the next window, select the main class to execute. In this case, select the App class and click on the Ok button. You will see the “Hello World” output in the Console window.
The maven-compiler-plugin uses javac by default, and binds by default to the compile lifecycle phase.
Create a pom-only ( <packaging>pom</packaging> ) project that has the compiler settings (and any other default settings) you want. You give treat it like any other project (release it; deploy it to your Maven repo, etc.). It doesn't help much if all you want to set is compiler settings.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With