LoginSignup
7
7

More than 5 years have passed since last update.

Maven の Eclipse プラグインで CheckStyle の設定を自動インポートするメモ

Posted at

Maven の Eclipse プラグインを使うとコマンド一発で Eclipse にインポート可能なプロジェクトを作ることができます。

mvn eclipse:eclipse

上記のコマンドを実行する際に、 pom.xml の設定で下記のようにすると、
CheckStyle の設定も自動で設定済みの状態にできます。

また、この方法を使えば、コードフォーマッタなども同様に初期化ができます。

pom.xml

   :   :   :
   :   :   :

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-eclipse-plugin</artifactId>
        <configuration>
          <additionalProjectnatures>
            <projectnature>org.eclipse.jdt.core.javanature</projectnature>
            <projectnature>org.eclipse.m2e.core.maven2Nature</projectnature>
            <projectnature>net.sf.eclipsecs.core.CheckstyleNature</projectnature>
          </additionalProjectnatures>
          <buildcommands>
            <buildcommand>org.eclipse.jdt.core.javabuilder</buildcommand>
            <buildcommand>org.eclipse.m2e.core.maven2Builder</buildcommand>
            <buildcommand>net.sf.eclipsecs.core.CheckstyleBuilder</buildcommand>
          </buildcommands>
          <classpathContainers>
            <classpathContainer>org.eclipse.jdt.launching.JRE_CONTAINER</classpathContainer>
            <classpathContainer>org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER</classpathContainer>
          </classpathContainers>
          <useProjectReferences>true</useProjectReferences>
          <additionalConfig>
            <file>
              <name>.checkstyle.xml</name> ←★CheckStyleの設定内容が書かれたファイル
              <content>
<![CDATA[ ★XMLファイルの中身★ ]]>
              </content>
            </file>
            <file>
              <name>.checkstyle</name>
              <content>
<![CDATA[<?xml version="1.0" encoding="UTF-8"?> ↓★ここでCheckStyleの設定ファイルをインポートする
<fileset-config file-format-version="1.2.0" simple-config="false" sync-formatter="false">
  <local-check-config name="MyCheckstyle" location=".checkstyle.xml" type="project" description="">
    <additional-data name="protect-config-file" value="false"/>
  </local-check-config>
  <fileset name="All" enabled="true" check-config-name="MyCheckstyle" local="true">
    <file-match-pattern match-pattern="^src/main/java/myproject/" include-pattern="true"/>
  </fileset>
</fileset-config>
]]>
              </content>
            </file>
          </additionalConfig>
        </configuration>
      </plugin>

   :   :   :
   :   :   :

7
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
7