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?
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.
The default Java compiler version used by Maven is Java 1.5 .
</descriptors> </configuration> </execution> <execution> <id>default-cli</id>
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 ( *.
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.
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.
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