LoginSignup
11
10

More than 5 years have passed since last update.

Mavenでビルドする際にpomによく書くことメモ

Posted at

Mavenでビルドする際に、Pom.xmlによく書くことメモ。

ソースコードのエンコード指定

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <java.version>1.8</java.version>
    </properties>

エンコードの指定は

[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!

というエラーを無くすため。

javaバージョンはmaven-compiler-pluginに渡して、JDK8でビルドさせるため。

コンパイルオプション付加用の変数

    <build>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.3</version>
                <configuration>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                    <compilerArgument>${compilerArgument}</compilerArgument>
                </configuration>
            </plugin>
        </plugins>
    </build>

compilerArgumentはコンパイルオプションを追加で指定するため。

というのも

 [javac] 注:詳細については、-Xlint:deprecation オプションを指定して再コンパイルしてください。

といったメッセージがコンパイル時に出ることがあるため、mvnコマンド時に上記のオプションを渡せるようにしたいので。

実際にコンパイルオプションを付ける場合は、以下のようにする。

$ mvn clean compile -DcompilerArgument=-Xlint:deprecation,unchecked

Xlintにはカンマ区切りで複数指定できるようだ。

11
10
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
11
10