Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

default maven compiler setting

Right now, I'm writing a small java application by my own, with few maven pom.xml files. I want to make all my maven packages to compile with jdk 1.6, and I can't find a good way to do it without manually setting it on every single POMs - I'm sick of copy-and-pasting

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

in every single pom.xml file I generate.

Is there a simpler way to resolve this issue?

like image 466
Jeeyoung Kim Avatar asked Mar 28 '10 02:03

Jeeyoung Kim


People also ask

How do I change my default Maven compiler?

Show activity on this post. 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.

What compiler does Maven use?

The default Java compiler version used by Maven is Java 1.5 .

What is default CLI Maven?

</descriptors> </configuration> </execution> <execution> <id>default-cli</id>

Is Maven compiler plugin necessary?

Maven Compiler Plugin might be the most important plugin in Maven. It is used to compile the sources of your project, which transform Java files ( *. java ) into class files ( *.


2 Answers

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.).

Put a parent declaration at the top of your pom files:

<parent>   <groupId><!-- parent's group id --></groupId>   <artifactId><!-- parent's artifact id --></artifactId>   <version><!-- parent's version --></version> </parent> 

It doesn't help much if all you want to set is compiler settings. But if you find yourself configuring lots of plugins, reports and dependencies in the same way across project, you can create one parent to rule them all.

BTW - be careful about declaring dependencies and plugins in your parent pom file. Usually you'll want to favor dependencyManagement and pluginManagement. See the documentation for more details.

like image 132
leedm777 Avatar answered Oct 04 '22 05:10

leedm777


You could specify this plugin and configuration in your ~/.m2/settings.xml, which will then apply it to all projects.

However this has the downside of making your projects no longer portable - attempting to build the same code with the same pom.xml will fail on other machines that don't have the same settings.xml values as you.

like image 42
matt b Avatar answered Oct 04 '22 05:10

matt b