How to configure Checkstyle in Eclipse for maven project automatically

I have a maven-multi project when I create a new eclipse project from it (according to M2E 1.0 "Checkout Maven Project from SCM). I want the eclipse checkstyle plugin to be configured for this project automatically.

So, I added the maven-eclipse-plugin section to the parent pom <pluginManagement> and configured it to create the .checkstyle file, as well as the additional character of the CheckstyleNature project. In modul poms, I added the name maven-eclipse-plugin in the build section. But when I check the project, nothing happens, the file is not generated and nature is not added.

So, I think I'm doing something completely wrong, but how is this done right?


Pom Pom Plugin Management Section:

 <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-eclipse-plugin</artifactId> <version>2.8</version> <configuration> <downloadSources>true</downloadSources> <downloadJavadocs>false</downloadJavadocs> <wtpversion>2.0</wtpversion> <additionalBuildcommands> <buildCommand> <name>org.eclipse.ajdt.core.ajbuilder</name> <arguments> <aspectPath>org.springframework.aspects</aspectPath> </arguments> </buildCommand> <buildCommand> <name>org.springframework.ide.eclipse.core.springbuilder</name> </buildCommand> </additionalBuildcommands> <additionalProjectnatures> <projectnature>org.eclipse.ajdt.ui.ajnature</projectnature> <projectnature>org.springframework.ide.eclipse.core.springnature</projectnature> <projectnature>com.atlassw.tools.eclipse.checkstyle.CheckstyleNature</projectnature> </additionalProjectnatures> <additionalConfig> <file> <name>.checkstyle</name> <content> <![CDATA[ <?xml version="1.0" encoding="UTF-8"?> <fileset-config file-format-version="1.2.0" simple-config="true" sync-formatter="false"> <fileset name="all" enabled="true" check-config-name="My Checkstyle rules" local="false"> <file-match-pattern match-pattern="." include-pattern="true"/> </fileset> <filter name="FilesFromPackage" enabled="true"> <filter-data value="target" /> <filter-data value="src/main/resources"/> <filter-data value="src/test/java"/> <filter-data value="src/test/resources"/> <filter-data value="src/main/webapp" /> </filter> </fileset-config> ]]> </content> </file> </additionalConfig> </configuration> </plugin> 

Pom module - plugins:

 <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-eclipse-plugin</artifactId> </plugin> 
+7
source share
3 answers

There are detailed answers to this topic in Can I configure m2eclipse via pom.xml? :

The fully automatic configuration of the Eclipse Checkstyle plugin can only be achieved with ProjectConfigurator, for example. m2e-code-quality or m2e-extensions .

For m2e version 1.0 you can install them through the m2e market under Preferences-> Maven-> Discovery β†’ "Open Directory". See error tracking for more details on integrating m2e code quality into the m2e market .

There is also a solution based on AntRun and XMLTask, even for FindBugs and Sonar. It is necessary for manual start only once after verification.

+5
source

The maven eclipse plugin is not the same as the m2e eclipse plugin, which I assume you are trying to use. Basically, you should not use both at the same time.

You can use mvn eclipse: eclipse from the command line to generate project files, and then you can import projects into eclipse. M2e works very differently and instead uses pom files when importing projects as maven plugins. You probably want to configure the checkstyle plugin and hopefully the eclipse picks up the settings. The same goes for findbugs and other maven plugins.

However, I really prefer to use mvn eclipse: eclipse and did not actually check the above working as expected. M2e is too much time for me and seems to go away and often do the wrong things. I especially hate how he has the habit of basically rebuilding everything after command line interaction with maven. But many people seem to like m2e.

+4
source

You must install the connector "Checkstyle m2e"

applies the maven-checkstyle-plugin configuration form to the eclipse checkstyle plugin

In the window \ preferences \ Maven \ Discover \ Open Catalog

And, of course, you need to change the pom so that the validation style plugin is configured, not the eclipse plugin.

Unfortunately this does not work for me! (I will not delete the answer because it may work for someone else.)

+1
source

All Articles