Mavenを利用したJavaのCIをGithub Actionで試してみました。
Mavanインストール
記事を参考にMavenをインストールする。
Javaプロジェクトを作成
mvnコマンドでJavaプロジェクトを作成する。
今回はGithubリポジトリをjava-test
で作成したので、-DartifactId=java-test
とした。
mvn archetype:generate -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false -DgroupId=com.sample -DartifactId=java-test
pom.xmlの追記
デフォルトのpom.xmlだとビルドエラーが発生する。
Error: Source option 5 is no longer supported. Use 6 or later.
Error: Target option 1.5 is no longer supported. Use 1.6 or later.
以下をpom.xmlに追記する。
pom.xml
+ <properties>
+ <maven.compiler.source>1.6</maven.compiler.source>
+ <maven.compiler.target>1.6</maven.compiler.target>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
workflow作成
今回はGithub ActionのJava with Maven
をそのまま利用した。
maven.yml
# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven
name: Java CI with Maven
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/setup-java@v2
with:
java-version: '11'
distribution: 'temurin'
cache: maven
- name: Build with Maven
run: mvn -B package --file pom.xml
.gitignoreの追加
Githubの例をそのまま利用した。
結果
CIできました!!