LoginSignup
6
0

More than 1 year has passed since last update.

Java with MavenのGithub Actionを動かしてみる

Last updated at Posted at 2022-03-14

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できました!!

image.png

6
0
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
6
0