Skip to content

Commit 1a65bdd

Browse files
ramsessanchezCopilotCopilot
authored
Migrate build infrastructure from Gradle to Maven (#2111)
* Migrate build infrastructure from Gradle to Maven Replaces the Gradle build with Maven while preserving build behaviors, and moves CI/CD off PAT usage. - New Maven build (pom.xml) with dependencies, compiler (-parameters, Java 1.8 main / 17 tests), jar Automatic-Module-Name, javadoc/source jars, jacoco, spotbugs, sonar, and a GPG signing profile - Maven wrapper (mvnw/mvnw.cmd/.mvn) replacing the Gradle wrapper - gradle-build.yml -> maven-build.yml; codeql-analysis.yml and sonarcloud.yml updated to Maven - ADO ci-build.yml and daily-ci-build.yml use Maven with PAT-less MavenAuthenticate and settings.xml mirror + GPG signing - dependabot.yml (maven root, gradle for /android), .gitignore, release-please-config.json, devx.yml, getLatestVersion.ps1, validatePackageContents.ps1 updated - android/ kept as standalone Gradle project with inlined dependencies - Removed root Gradle files and the java-8 sub-project (Java 8 verified via Maven source/target 1.8 + JDK 8 CI job) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix save * Ignore jakarta.annotation-api major (v3) updates in Dependabot jakarta.annotation-api 3.x is compiled to Java 11 bytecode, incompatible with the library's Java 8 baseline, so pin to the 2.x line. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * bump azure and kiota * Ignore okhttp major (v5) updates in Dependabot okhttp 5.x is a major bump that will be handled manually; pin to the 4.x line in both the Maven and Android ecosystems. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Align android dependencies with pom (azure-core 1.58.1, kiota 1.9.3) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Ignore android lint newer-version warnings for okhttp and jakarta Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Remove dependabot ignore for okhttp major bump Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
1 parent c570ace commit 1a65bdd

32 files changed

Lines changed: 1106 additions & 877 deletions

.azure-pipelines/ci-build.yml

Lines changed: 52 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -65,29 +65,62 @@ extends:
6565
Copy-Item $(downloadLocalProperties.secureFilePath) local.properties -Verbose
6666
displayName: Copy secring and 'local.properties'
6767
68-
- script: ./gradlew --no-daemon publishToMavenLocal -PmavenCentralPublishingEnabled=true -PmavenCentralSnapshotArtifactSuffix=""
69-
displayName: Publish to local Maven for verification
70-
condition: contains(variables['build.sourceBranch'], 'refs/tags/v')
68+
- pwsh: |
69+
# maven-gpg-plugin signs via the local gpg keyring, so the key from
70+
# secring.gpg must be imported into gpg before signing can succeed.
71+
gpg --batch --import secring.gpg
72+
displayName: Import GPG signing key
7173
72-
- script: ./gradlew --no-daemon publishToMavenLocal -PmavenCentralPublishingEnabled=true
73-
displayName: Publish to local Maven for verification
74-
condition: not(contains(variables['build.sourceBranch'], 'refs/tags/v'))
74+
- pwsh: |
75+
$props = Get-Content local.properties -Raw
76+
$keyId = ($props | Select-String -Pattern 'signing\.keyId=(.+)').Matches.Groups[1].Value
77+
$keyPassword = ($props | Select-String -Pattern 'signing\.password=(.+)').Matches.Groups[1].Value
78+
79+
$settingsXml = @"
80+
<settings>
81+
<mirrors>
82+
<mirror>
83+
<id>GraphDeveloperExperiences_Public</id>
84+
<mirrorOf>*</mirrorOf>
85+
<url>https://microsoftgraph.pkgs.visualstudio.com/0985d294-5762-4bc2-a565-161ef349ca3e/_packaging/GraphDeveloperExperiences_Public/maven/v1</url>
86+
</mirror>
87+
</mirrors>
88+
<profiles>
89+
<profile>
90+
<id>signing</id>
91+
<properties>
92+
<gpg.keyname>$keyId</gpg.keyname>
93+
<gpg.passphrase>$keyPassword</gpg.passphrase>
94+
</properties>
95+
</profile>
96+
</profiles>
97+
</settings>
98+
"@
99+
$settingsDir = Join-Path $HOME ".m2"
100+
New-Item -ItemType Directory -Path $settingsDir -Force | Out-Null
101+
$settingsXml | Set-Content (Join-Path $settingsDir "settings.xml") -Encoding UTF8
102+
displayName: Configure Maven settings
103+
104+
- task: MavenAuthenticate@0
105+
displayName: Authenticate to Azure Artifacts feed (PAT-less)
106+
inputs:
107+
artifactsFeeds: 'GraphDeveloperExperiences_Public'
75108

76-
- script: ./gradlew --no-daemon publishMavenPublicationToADORepository -PmavenCentralPublishingEnabled=true -PmavenCentralSnapshotArtifactSuffix=""
77-
displayName: Publish to local Maven ADO for ESRP
78-
condition: contains(variables['build.sourceBranch'], 'refs/tags/v')
109+
- script: ./mvnw install -Psigning --no-transfer-progress
110+
displayName: Publish to local Maven for verification
79111

80-
- script: ./gradlew --no-daemon publishMavenPublicationToADORepository -PmavenCentralPublishingEnabled=true
81-
displayName: Publish to local Maven ADO for ESRP
82-
condition: not(contains(variables['build.sourceBranch'], 'refs/tags/v'))
112+
- script: ./mvnw deploy -Psigning --no-transfer-progress -DaltDeploymentRepository=ADO::default::file://$(Build.SourcesDirectory)/target/staging-deploy
113+
displayName: Stage artifacts for ESRP
83114

84115
- pwsh: |
85-
$contents = Get-Content gradle.properties -Raw
86-
$major = $contents | Select-String -Pattern 'mavenMajorVersion\s*=\s*([0-9]+)' | ForEach-Object { $_.Matches.Groups[1].Value }
87-
$minor = $contents | Select-String -Pattern 'mavenMinorVersion\s*=\s*([0-9]+)' | ForEach-Object { $_.Matches.Groups[1].Value }
88-
$patch = $contents | Select-String -Pattern 'mavenPatchVersion\s*=\s*([0-9]+)' | ForEach-Object { $_.Matches.Groups[1].Value }
89-
$snapshot_suffix = if ($Env:BRANCH_NAME.StartsWith('refs/tags/v')) { '' } else { '-SNAPSHOT' }
90-
$version = "$major.$minor.$patch$snapshot_suffix"
116+
$pomXml = [xml](Get-Content pom.xml -Raw)
117+
$ns = New-Object System.Xml.XmlNamespaceManager($pomXml.NameTable)
118+
$ns.AddNamespace('m', $pomXml.DocumentElement.NamespaceURI)
119+
$version = $pomXml.SelectSingleNode('/m:project/m:version', $ns).InnerText
120+
# If version contains -SNAPSHOT and we're on a tag, strip it
121+
if ($Env:BRANCH_NAME.StartsWith('refs/tags/v')) {
122+
$version = $version -replace '-SNAPSHOT$', ''
123+
}
91124
echo "Current version is $version"
92125
echo "##vso[task.setvariable variable=PACKAGE_VERSION;]$version"
93126
displayName: Get current version
@@ -100,7 +133,7 @@ extends:
100133
displayName: Inspect contents of local Maven cache
101134
102135
- pwsh: |
103-
$packageFullPath = Join-Path -Path "./" -ChildPath "build/publishing-repository/com/microsoft/graph/microsoft-graph-core" -AdditionalChildPath "$(PACKAGE_VERSION)"
136+
$packageFullPath = Join-Path -Path "./target/staging-deploy" -ChildPath "com/microsoft/graph/microsoft-graph-core" -AdditionalChildPath "$(PACKAGE_VERSION)"
104137
echo "Package full path: $packageFullPath"
105138
echo "##vso[task.setvariable variable=PACKAGE_PATH;]$packageFullPath"
106139
displayName: Get the package full path
@@ -176,16 +209,6 @@ extends:
176209
$(Pipeline.Workspace)/**/*.pom.asc.sha1
177210
$(Pipeline.Workspace)/**/*.pom.asc.sha256
178211
$(Pipeline.Workspace)/**/*.pom.asc.sha512
179-
$(Pipeline.Workspace)/**/*.module
180-
$(Pipeline.Workspace)/**/*.module.md5
181-
$(Pipeline.Workspace)/**/*.module.sha1
182-
$(Pipeline.Workspace)/**/*.module.sha256
183-
$(Pipeline.Workspace)/**/*.module.sha512
184-
$(Pipeline.Workspace)/**/*.module.asc
185-
$(Pipeline.Workspace)/**/*.module.asc.md5
186-
$(Pipeline.Workspace)/**/*.module.asc.sha1
187-
$(Pipeline.Workspace)/**/*.module.asc.sha256
188-
$(Pipeline.Workspace)/**/*.module.asc.sha512
189212
190213
addChangeLog: false
191214
action: edit

.azure-pipelines/daily-ci-build.yml

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -43,26 +43,47 @@ extends:
4343
- checkout: self
4444
submodules: recursive
4545

46-
- script: |
47-
sed -i "/com.github.spotbugs/d" build.gradle
48-
sed -i "/org.sonarqube/d" build.gradle
49-
sed -i "/spotbugsMain/,/^}/d" build.gradle
50-
sed -i "/spotbugsTest/,/^}/d" build.gradle
51-
sed -i "/sonarqube {/,/^}/d" build.gradle
52-
sed -i "/mavenCentral()/d" build.gradle
53-
sed -i "/gradlePluginPortal()/d" settings.gradle
54-
sed -i "/mavenCentral()/d" settings.gradle
55-
displayName: Strip plugins and public repos for network-isolated build
46+
- task: JavaToolInstaller@1
47+
inputs:
48+
versionSpec: '17'
49+
jdkArchitectureOption: 'x64'
50+
jdkSourceOption: 'PreInstalled'
51+
52+
- pwsh: |
53+
# Route all Maven resolution through the Azure Artifacts feed (Maven Central upstream)
54+
# so the network-isolated build never reaches the public internet. Credentials for the
55+
# mirror are injected PAT-less by the MavenAuthenticate task below; the mirror <id> must
56+
# match the <server> id it generates (the feed name).
57+
$settingsXml = @"
58+
<settings>
59+
<mirrors>
60+
<mirror>
61+
<id>GraphDeveloperExperiences_Public</id>
62+
<mirrorOf>*</mirrorOf>
63+
<url>https://microsoftgraph.pkgs.visualstudio.com/0985d294-5762-4bc2-a565-161ef349ca3e/_packaging/GraphDeveloperExperiences_Public/maven/v1</url>
64+
</mirror>
65+
</mirrors>
66+
</settings>
67+
"@
68+
$settingsDir = Join-Path $HOME ".m2"
69+
New-Item -ItemType Directory -Path $settingsDir -Force | Out-Null
70+
$settingsXml | Set-Content (Join-Path $settingsDir "settings.xml") -Encoding UTF8
71+
displayName: Configure Maven mirror for network-isolated build
72+
73+
- task: MavenAuthenticate@0
74+
displayName: Authenticate to Azure Artifacts feed (PAT-less)
75+
inputs:
76+
artifactsFeeds: 'GraphDeveloperExperiences_Public'
5677

57-
- task: Gradle@4
78+
- task: Maven@4
5879
displayName: Build and Test SDK
5980
inputs:
60-
gradleWrapperFile: 'gradlew'
61-
workingDirectory: '$(Build.SourcesDirectory)'
62-
tasks: 'assemble test'
63-
options: '--no-daemon -PGraphDeveloperExperiencesPublicPassword=$(ARTIFACTS_PAT)'
81+
mavenPomFile: 'pom.xml'
82+
goals: 'verify'
83+
options: '--no-transfer-progress'
6484
publishJUnitResults: true
65-
testResultsFiles: '**/TEST-*.xml'
85+
testResultsFiles: '**/surefire-reports/TEST-*.xml'
6686
javaHomeOption: 'JDKVersion'
6787
jdkVersionOption: '1.17'
6888
jdkArchitectureOption: 'x64'
89+
mavenOptions: '-Xmx3072m'

.github/dependabot.yml

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
version: 2
22
updates:
3-
- package-ecosystem: gradle
4-
directories:
5-
- "/"
6-
- "/java-8"
3+
- package-ecosystem: maven
4+
directory: "/"
75
schedule:
86
interval: daily
97
time: "09:00" # 9am UTC
108
open-pull-requests-limit: 10
9+
ignore:
10+
# jakarta.annotation-api 3.x is compiled to Java 11 bytecode, which is
11+
# incompatible with this library's Java 8 baseline. Stay on the 2.x line.
12+
- dependency-name: "jakarta.annotation:jakarta.annotation-api"
13+
update-types: ["version-update:semver-major"]
1114
groups:
1215
kiota-dependencies:
1316
patterns:
@@ -24,21 +27,11 @@ updates:
2427
interval: daily
2528
time: "10:00" # 10am UTC. After core dependencies are updated to prevent duplicates.
2629
open-pull-requests-limit: 10
27-
groups:
28-
kiota-dependencies:
29-
patterns:
30-
- "*kiota*"
31-
junit-dependencies:
32-
patterns:
33-
- "*junit*"
34-
open-telemetry:
35-
patterns:
36-
- "*opentelemetry*"
37-
- package-ecosystem: maven
38-
directory: "/"
39-
schedule:
40-
interval: daily
41-
open-pull-requests-limit: 10
30+
ignore:
31+
# jakarta.annotation-api 3.x is compiled to Java 11 bytecode, which is
32+
# incompatible with this library's Java 8 baseline. Stay on the 2.x line.
33+
- dependency-name: "jakarta.annotation:jakarta.annotation-api"
34+
update-types: ["version-update:semver-major"]
4235
groups:
4336
kiota-dependencies:
4437
patterns:

.github/workflows/codeql-analysis.yml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ jobs:
4949
with:
5050
java-version: 21
5151
distribution: 'temurin'
52-
cache: gradle
52+
cache: maven
5353

5454
# Initializes the CodeQL tools for scanning.
5555
- name: Initialize CodeQL
@@ -75,10 +75,8 @@ jobs:
7575
# If the Autobuild fails above, remove it and uncomment the following three lines.
7676
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.
7777

78-
- name: Grant execute permission for gradlew
79-
run: chmod +x gradlew
80-
- name: Build with Gradle
81-
run: ./gradlew build
78+
- name: Build with Maven
79+
run: ./mvnw compile --no-transfer-progress -DskipTests
8280

8381
- name: Perform CodeQL Analysis
8482
uses: github/codeql-action/analyze@v4

.github/workflows/gradle-build.yml

Lines changed: 0 additions & 40 deletions
This file was deleted.

.github/workflows/maven-build.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Maven Build
2+
3+
on:
4+
pull_request:
5+
branches: [main, support/2.x.x]
6+
workflow_dispatch:
7+
8+
jobs:
9+
build-java-latest:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v6
13+
- name: Set up JDK
14+
uses: actions/setup-java@v5
15+
with:
16+
java-version: 21
17+
distribution: 'temurin'
18+
cache: maven
19+
- name: Build with Maven
20+
run: ./mvnw verify --no-transfer-progress
21+
- name: Upload Unit Test Results
22+
if: ${{ always() }}
23+
uses: actions/upload-artifact@v7
24+
with:
25+
name: UnitTests
26+
path: |
27+
target/surefire-reports/**
28+
- name: Upload a Build Artifact
29+
uses: actions/upload-artifact@v7
30+
with:
31+
name: drop
32+
path: |
33+
target/*.jar
34+
pom.xml
35+
mvnw
36+
mvnw.cmd
37+
.mvn/**
38+
scripts/**
39+
40+
build-java-8:
41+
runs-on: ubuntu-latest
42+
steps:
43+
- uses: actions/checkout@v6
44+
- name: Set up JDK
45+
uses: actions/setup-java@v5
46+
with:
47+
java-version: 8
48+
distribution: 'temurin'
49+
cache: maven
50+
- name: Build with Java 8
51+
run: ./mvnw compile --no-transfer-progress

.github/workflows/sonarcloud.yml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,14 @@ jobs:
3434
with:
3535
java-version: 21
3636
distribution: 'temurin'
37-
cache: gradle
37+
cache: maven
3838
- name: Cache SonarCloud packages
3939
uses: actions/cache@v5
4040
with:
4141
path: ~/.sonar/cache
4242
key: ${{ runner.os }}-sonar
4343
restore-keys: ${{ runner.os }}-sonar
44-
- name: Cache Gradle packages
45-
uses: actions/cache@v5
46-
with:
47-
path: ~/.gradle/caches
48-
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}
49-
restore-keys: ${{ runner.os }}-gradle
5044
- name: Build and analyze
5145
env:
5246
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
53-
run: ./gradlew build sonarqube --info
47+
run: ./mvnw verify sonar:sonar --no-transfer-progress -Dsonar.token=$SONAR_TOKEN

.gitignore

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,12 @@
2020

2121
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
2222
hs_err_pid*
23-
/.gradle/
24-
/build/
25-
/bin/
23+
24+
# Maven
25+
/target/
26+
27+
# Maven wrapper
28+
!.mvn/wrapper/maven-wrapper.jar
2629

2730
#Eclipse
2831
.project
@@ -33,7 +36,5 @@ hs_err_pid*
3336
*.iml
3437
.idea/
3538

36-
# Maven
37-
/target/
3839
local.properties
3940
*.gpg

.mvn/wrapper/maven-wrapper.jar

61.6 KB
Binary file not shown.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.9/apache-maven-3.9.9-bin.zip
2+
distributionSha256Sum=4ec3f26fb1a692473aea0235c300bd20f0f9fe741947c82c1234cefd76ac3a3c
3+
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.3.2/maven-wrapper-3.3.2.jar
4+
wrapperSha256Sum=3d8f20ce6103913be8b52aef6d994e0c54705fb527324ceb9b835b338739c7a8

0 commit comments

Comments
 (0)