actions / setup-java

Set up your GitHub Actions workflow with a specific version of Java
MIT License
1.51k stars 730 forks source link

How to get a newer maven version alongside JDK 17 #685

Closed ghoshbishakh closed 1 day ago

ghoshbishakh commented 6 days ago

Description:

After setting up JDK 17, the maven version we get is 3.8.8 We want to get the latest maven version, 3.9.x

Here is the workflow:

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      - name: Set up JDK
        uses: actions/setup-java@v4
        with:
          java-version: '17'
          distribution: 'temurin'
      - run: mvn --version

Task version: v4

Platform:

Runner type:

aparnajyothi-y commented 5 days ago

Hello @ghoshbishakh, Thank you for creating this issue and we will look into it :)

gowridurgad commented 1 day ago

Hi @ghoshbishakh, To use Maven version 3.9.9 alongside JDK 17, Maven needs to be manually installed since the ubuntu-latest runner image comes with Maven 3.8.8 by default. For reference, please visit https://github.com/actions/runner-images/blob/main/images/ubuntu/Ubuntu2204-Readme.md. Here is an updated workflow configuration:

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      - name: Install latest Maven
        run: |
          MAVEN_VERSION=3.9.9
          wget https://downloads.apache.org/maven/maven-3/$MAVEN_VERSION/binaries/apache-maven-$MAVEN_VERSION-bin.tar.gz
          tar xzvf apache-maven-$MAVEN_VERSION-bin.tar.gz
          sudo mv apache-maven-$MAVEN_VERSION /opt/maven
          sudo rm -f /usr/bin/mvn  # Remove existing symbolic link if it exists
          sudo ln -s /opt/maven/bin/mvn /usr/bin/mvn  # Create new symbolic link
      - name: Set up JDK
        uses: actions/setup-java@v4
        with:
          java-version: '17'
          distribution: 'temurin' 
      - run: mvn --version
ghoshbishakh commented 1 day ago

Thanks a lot @gowridurgad . I will try it out.