Skip to content

Commit acdfb18

Browse files
chore: centralize Java version configuration in composite action (#38)
Create a reusable composite action (.github/actions/setup-java) to centralize Java version configuration across all workflows. This eliminates duplication and makes future Java version updates single-point changes. Changes: - Add .github/actions/setup-java/action.yml with Java 25 + Temurin - Update build-and-publish.yml to use composite action - Update release-publish.yml to use composite action - Update nightly-build.yml to use composite action - Update atr-release.yml to use composite action - Update atr-release-test.yml to use composite action - Remove redundant env variables (JAVA_VERSION, JAVA_DISTRIBUTION) - Remove duplicate chmod +x gradlew steps (now in composite action) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 705bc5f commit acdfb18

6 files changed

Lines changed: 74 additions & 87 deletions

File tree

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one or more
2+
# contributor license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright ownership.
4+
# The ASF licenses this file to You under the Apache License, Version 2.0
5+
# (the "License"); you may not use this file except in compliance with
6+
# the License. You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
# Composite action for setting up Java environment
17+
# Centralizes Java version configuration to avoid duplication across workflows
18+
#
19+
# Usage in workflows:
20+
# - uses: ./.github/actions/setup-java
21+
#
22+
# To update Java version, change JAVA_VERSION below.
23+
# All workflows using this action will automatically use the new version.
24+
25+
name: 'Setup Java'
26+
description: 'Set up Java environment with Gradle caching'
27+
28+
outputs:
29+
java-version:
30+
description: 'The Java version that was set up'
31+
value: ${{ steps.setup.outputs.version }}
32+
33+
runs:
34+
using: 'composite'
35+
steps:
36+
- name: Set up JDK
37+
id: setup
38+
uses: actions/setup-java@v4
39+
with:
40+
# ============================================
41+
# CENTRALIZED JAVA VERSION CONFIGURATION
42+
# Change this value to update Java across all workflows
43+
# ============================================
44+
java-version: '25'
45+
distribution: 'temurin'
46+
cache: 'gradle'
47+
48+
- name: Grant execute permission for gradlew
49+
shell: bash
50+
run: chmod +x gradlew

.github/workflows/atr-release-test.yml

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,6 @@ permissions:
9595
packages: write # May be needed for publishing artifacts
9696

9797
env:
98-
JAVA_VERSION: '25'
99-
JAVA_DISTRIBUTION: 'temurin'
10098
ATR_PROJECT_NAME: 'solr-mcp' # Project identifier in ATR platform
10199

102100
jobs:
@@ -128,15 +126,10 @@ jobs:
128126
echo "Test tag already exists: ${TEST_TAG}"
129127
fi
130128
131-
- name: Set up JDK ${{ env.JAVA_VERSION }}
132-
uses: actions/setup-java@v4
133-
with:
134-
java-version: ${{ env.JAVA_VERSION }}
135-
distribution: ${{ env.JAVA_DISTRIBUTION }}
136-
cache: 'gradle'
137-
138-
- name: Grant execute permission for gradlew
139-
run: chmod +x gradlew
129+
# Set up Java environment using centralized configuration
130+
# See .github/actions/setup-java/action.yml to update Java version
131+
- name: Set up Java
132+
uses: ./.github/actions/setup-java
140133

141134
- name: Build project
142135
run: |

.github/workflows/atr-release.yml

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,6 @@ permissions:
137137
packages: write # May be needed for publishing artifacts
138138

139139
env:
140-
JAVA_VERSION: '25'
141-
JAVA_DISTRIBUTION: 'temurin'
142140
ATR_PROJECT_NAME: 'solr-mcp' # Project identifier in ATR platform
143141

144142
jobs:
@@ -167,15 +165,10 @@ jobs:
167165
fi
168166
echo "✓ Release tag verified"
169167
170-
- name: Set up JDK ${{ env.JAVA_VERSION }}
171-
uses: actions/setup-java@v4
172-
with:
173-
java-version: ${{ env.JAVA_VERSION }}
174-
distribution: ${{ env.JAVA_DISTRIBUTION }}
175-
cache: 'gradle'
176-
177-
- name: Grant execute permission for gradlew
178-
run: chmod +x gradlew
168+
# Set up Java environment using centralized configuration
169+
# See .github/actions/setup-java/action.yml to update Java version
170+
- name: Set up Java
171+
uses: ./.github/actions/setup-java
179172

180173
- name: Build project
181174
run: |

.github/workflows/build-and-publish.yml

Lines changed: 8 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,6 @@ on:
109109
- main # Build + test validation for incoming changes
110110
workflow_dispatch: # Manual runs for maintainers
111111

112-
# Global environment used by all jobs in this workflow
113-
# - JAVA_VERSION: JDK version to install for Gradle builds
114-
# - JAVA_DISTRIBUTION: Vendor/distribution of the JDK (Temurin is Eclipse Adoptium)
115-
env:
116-
JAVA_VERSION: '25'
117-
JAVA_DISTRIBUTION: 'temurin'
118-
119112
jobs:
120113
# ============================================================================
121114
# Job 1: Build JAR
@@ -138,20 +131,10 @@ jobs:
138131
- name: Checkout code
139132
uses: actions/checkout@v4
140133

141-
# Set up Java Development Kit
142-
# Uses Temurin (Eclipse Adoptium) distribution of OpenJDK 25
143-
# Gradle cache is enabled to speed up subsequent builds
144-
- name: Set up JDK ${{ env.JAVA_VERSION }}
145-
uses: actions/setup-java@v4
146-
with:
147-
java-version: ${{ env.JAVA_VERSION }}
148-
distribution: ${{ env.JAVA_DISTRIBUTION }}
149-
cache: 'gradle'
150-
151-
# Make the Gradle wrapper executable
152-
# Required on Unix-based systems (Linux, macOS)
153-
- name: Grant execute permission for gradlew
154-
run: chmod +x gradlew
134+
# Set up Java environment using centralized configuration
135+
# See .github/actions/setup-java/action.yml to update Java version
136+
- name: Set up Java
137+
uses: ./.github/actions/setup-java
155138

156139
# Build the project with Gradle
157140
# This runs: compilation, tests, spotless formatting, error-prone checks,
@@ -228,18 +211,10 @@ jobs:
228211
- name: Checkout code
229212
uses: actions/checkout@v4
230213

231-
# Set up Java for running Jib
232-
# Jib doesn't require Docker but needs Java to run
233-
- name: Set up JDK ${{ env.JAVA_VERSION }}
234-
uses: actions/setup-java@v4
235-
with:
236-
java-version: ${{ env.JAVA_VERSION }}
237-
distribution: ${{ env.JAVA_DISTRIBUTION }}
238-
cache: 'gradle'
239-
240-
# Make Gradle wrapper executable
241-
- name: Grant execute permission for gradlew
242-
run: chmod +x gradlew
214+
# Set up Java environment using centralized configuration
215+
# See .github/actions/setup-java/action.yml to update Java version
216+
- name: Set up Java
217+
uses: ./.github/actions/setup-java
243218

244219
# Extract version and determine image tags
245220
# Outputs:

.github/workflows/nightly-build.yml

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,6 @@ on:
9191
type: boolean
9292
default: false
9393

94-
# Environment variables used by steps below
95-
# - JAVA_VERSION: selects the JDK version used to build and run Gradle
96-
# - JAVA_DISTRIBUTION: selects the vendor (Temurin = Eclipse Adoptium)
97-
env:
98-
JAVA_VERSION: '25'
99-
JAVA_DISTRIBUTION: 'temurin'
100-
10194
jobs:
10295
nightly-build:
10396
name: Nightly Build and Publish
@@ -114,15 +107,10 @@ jobs:
114107
- name: Checkout code
115108
uses: actions/checkout@v4
116109

117-
- name: Set up JDK ${{ env.JAVA_VERSION }}
118-
uses: actions/setup-java@v4
119-
with:
120-
java-version: ${{ env.JAVA_VERSION }}
121-
distribution: ${{ env.JAVA_DISTRIBUTION }}
122-
cache: 'gradle'
123-
124-
- name: Grant execute permission for gradlew
125-
run: chmod +x gradlew
110+
# Set up Java environment using centralized configuration
111+
# See .github/actions/setup-java/action.yml to update Java version
112+
- name: Set up Java
113+
uses: ./.github/actions/setup-java
126114

127115
- name: Generate nightly version
128116
id: version

.github/workflows/release-publish.yml

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,6 @@ on:
125125
type: boolean
126126
default: false
127127

128-
# Global environment settings used across jobs
129-
# - JAVA_VERSION: version of JDK used to build the project
130-
# - JAVA_DISTRIBUTION: OpenJDK distribution to install via actions/setup-java
131-
env:
132-
JAVA_VERSION: '25'
133-
JAVA_DISTRIBUTION: 'temurin'
134-
135128
jobs:
136129
validate-release:
137130
name: Validate Release Prerequisites
@@ -187,15 +180,10 @@ jobs:
187180
with:
188181
ref: "v${{ inputs.release_version }}-${{ inputs.release_candidate }}"
189182

190-
- name: Set up JDK ${{ env.JAVA_VERSION }}
191-
uses: actions/setup-java@v4
192-
with:
193-
java-version: ${{ env.JAVA_VERSION }}
194-
distribution: ${{ env.JAVA_DISTRIBUTION }}
195-
cache: 'gradle'
196-
197-
- name: Grant execute permission for gradlew
198-
run: chmod +x gradlew
183+
# Set up Java environment using centralized configuration
184+
# See .github/actions/setup-java/action.yml to update Java version
185+
- name: Set up Java
186+
uses: ./.github/actions/setup-java
199187

200188
- name: Update version in build.gradle.kts
201189
run: |

0 commit comments

Comments
 (0)