8

After starting Eclipse, Mven seems to set the compiler settings to 1.5 and forget all the other global code style settings to ensure a higher code quality.

Is there some way to disable this feature? Or can I specify all compiler and code style checks in my POM?

It is very annoying because Ecplise can't run the app because of not allowed override annotations for interfaces. The tick in Java compiler -> Enable project specific settings is always set after a restart.

Eve Freeman
  • 32,467
  • 4
  • 86
  • 101
Franz Kafka
  • 10,623
  • 20
  • 93
  • 149

3 Answers3

5

You can set the compiler source and target (byte-code) versions in your pom.
See http://maven.apache.org/plugins/maven-compiler-plugin/examples/set-compiler-source-and-target.html

Code style checks can be configured in the pom as part of the maven reports, see http://maven.apache.org/plugins/maven-checkstyle-plugin/
but I'm not sure whether the integration will pick these up.

crowne
  • 8,456
  • 3
  • 35
  • 50
  • 2
    I would be happier if I can just turn off maven messing up my java settings. Why must if always put that tick into that box? Having a default at 1.5 is terrible. – Franz Kafka Jan 10 '12 at 20:19
  • 3
    @FranzKafka, one of the things that Maven is focused on providing are compatible builds. If you tried building your application through the command line or on a CI tool, they'll try building it on 1.5 because that is currently Maven's default. If you specify the source/target information, m2e will use the correct settings. – deterb Jan 11 '12 at 15:16
  • It's okay, I though it also changes the Eclipse code style checks, but they are seemingly untouched. – Franz Kafka Jan 11 '12 at 16:59
4

The simplest way is to add to your POM

<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
 <source>1.6</source>
 <target>1.6</target>
</configuration>

See default maven compiler setting for another solutions.

Community
  • 1
  • 1
alexsmail
  • 5,661
  • 7
  • 37
  • 57
  • To complement this, take a look at http://code.google.com/p/m2e-extensions/wiki/HomePage?tm=6, which provide a number of additional quality control plugins which add configuration based on your pom. – deterb Jan 11 '12 at 15:29
3

If you don't want the m2e eclipse plugin actively messing with your project settings, use the maven-eclipse-plugin's eclipse goal to generate your eclipse settings.

It'll generate your eclipse settings based off of what you have in your pom, so you'll still need to set the maven compiler settings in your pom if you don't want to set them every time you regenerate your eclipse project files when you update your pom.

If you take a look at the detailed configuration for that plugin, there are instructions for how to generate various pieces of eclipse metadata.

deterb
  • 3,994
  • 1
  • 28
  • 33