Skip to content

Commit d352b57

Browse files
ramsessanchezCopilotCopilot
authored
build: migrate build infrastructure from Gradle to Maven (#1346)
* build: migrate build infrastructure from Gradle to Maven Migrates the build system from Gradle to Maven, mirroring the v1 SDK migration (microsoftgraph/msgraph-sdk-java#2613), and moves CI/CD away from PAT-based Azure Artifacts auth to PAT-less MavenAuthenticate. - Add pom.xml, Maven wrapper (mvnw/mvnw.cmd/.mvn) - Replace gradle-build.yml with maven-build.yml; update codeql to mvnw - Update ADO ci-build.yml and daily-ci-build.yml to Maven + MavenAuthenticate@0 - dependabot: root -> maven, /android kept as gradle - release-please: xml xpath updater for pom.xml version - android: inline dependencies; remove shared gradle/dependencies.gradle - Remove all root Gradle files and the java-8 subproject Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix: make mvnw executable and raise javadoc heap for large beta SDK - Set the executable bit on mvnw so Linux CI (GitHub Actions) can run it (was failing with exit 126 / Permission denied) - Increase maven-javadoc-plugin fork heap to -J-Xmx4g; the beta SDK has 27,817 source files and OOMed javadoc at 2g (Please increase memory) 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 82bf9f1 commit d352b57

26 files changed

Lines changed: 910 additions & 750 deletions

.azure-pipelines/ci-build.yml

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

77-
- script: ./gradlew publishToMavenLocal -PmavenCentralPublishingEnabled=true
117+
- script: ./mvnw install -Psigning --no-transfer-progress
78118
displayName: Publish to local Maven for verification
79119
condition: not(contains(variables['build.sourceBranch'], 'refs/tags/v'))
80120

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

85-
- script: ./gradlew publishMavenPublicationToADORepository -PmavenCentralPublishingEnabled=true
86-
displayName: Publish to local Maven ADO for ESRP
125+
- script: ./mvnw deploy -Psigning --no-transfer-progress -DaltDeploymentRepository=ADO::default::file://$(Build.SourcesDirectory)/target/staging-deploy
126+
displayName: Stage artifacts for ESRP
87127
condition: not(contains(variables['build.sourceBranch'], 'refs/tags/v'))
88128

89129
- pwsh: |
90-
$contents = Get-Content gradle.properties -Raw
91-
$major = $contents | Select-String -Pattern 'mavenMajorVersion\s*=\s*([0-9]+)' | ForEach-Object { $_.Matches.Groups[1].Value }
92-
$minor = $contents | Select-String -Pattern 'mavenMinorVersion\s*=\s*([0-9]+)' | ForEach-Object { $_.Matches.Groups[1].Value }
93-
$patch = $contents | Select-String -Pattern 'mavenPatchVersion\s*=\s*([0-9]+)' | ForEach-Object { $_.Matches.Groups[1].Value }
130+
$pomXml = [xml](Get-Content pom.xml -Raw)
131+
$ns = New-Object System.Xml.XmlNamespaceManager($pomXml.NameTable)
132+
$ns.AddNamespace('m', $pomXml.DocumentElement.NamespaceURI)
133+
$version = $pomXml.SelectSingleNode('/m:project/m:version', $ns).InnerText
94134
$snapshot_suffix = if ($Env:BRANCH_NAME.StartsWith('refs/tags/v')) { '' } else { '-SNAPSHOT' }
95-
$version = "$major.$minor.$patch$snapshot_suffix"
135+
# If version already contains -SNAPSHOT and we're on a tag, strip it
136+
if ($Env:BRANCH_NAME.StartsWith('refs/tags/v')) {
137+
$version = $version -replace '-SNAPSHOT$', ''
138+
}
96139
echo "Current version is $version"
97140
echo "##vso[task.setvariable variable=PACKAGE_VERSION;]$version"
98141
displayName: Get current version
@@ -105,7 +148,7 @@ extends:
105148
displayName: Inspect contents of local Maven cache
106149
107150
- pwsh: |
108-
$packageFullPath = Join-Path -Path "./" -ChildPath "build/publishing-repository/com/microsoft/graph/microsoft-graph-beta" -AdditionalChildPath "$(PACKAGE_VERSION)"
151+
$packageFullPath = Join-Path -Path "./target/staging-deploy" -ChildPath "com/microsoft/graph/microsoft-graph-beta" -AdditionalChildPath "$(PACKAGE_VERSION)"
109152
echo "Package full path: $packageFullPath"
110153
echo "##vso[task.setvariable variable=PACKAGE_PATH;]$packageFullPath"
111154
displayName: Get the package full path

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

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

46-
- script: |
47-
sed -i "/mavenCentral()/d" build.gradle
48-
sed -i "/gradlePluginPortal()/d" settings.gradle
49-
sed -i "/mavenCentral()/d" settings.gradle
50-
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'
5177

52-
- task: Gradle@4
78+
- task: Maven@4
5379
displayName: Build and Test SDK
5480
inputs:
55-
gradleWrapperFile: 'gradlew'
56-
workingDirectory: '$(Build.SourcesDirectory)'
57-
tasks: 'assemble test'
58-
options: '--no-daemon -PGraphDeveloperExperiencesPublicPassword=$(ARTIFACTS_PAT)'
81+
mavenPomFile: 'pom.xml'
82+
goals: 'verify'
83+
options: '--no-transfer-progress'
5984
publishJUnitResults: true
60-
testResultsFiles: '**/TEST-*.xml'
85+
testResultsFiles: '**/surefire-reports/TEST-*.xml'
6186
javaHomeOption: 'JDKVersion'
6287
jdkVersionOption: '1.17'
6388
jdkArchitectureOption: 'x64'
89+
mavenOptions: '-Xmx3072m'

.github/dependabot.yml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
version: 2
22
updates:
3-
- package-ecosystem: gradle
4-
directories:
5-
- "/"
6-
- "/java-8"
7-
- "/android"
3+
- package-ecosystem: maven
4+
directory: "/"
85
schedule:
96
interval: weekly
107
time: "09:00" # 9am UTC
@@ -22,6 +19,13 @@ updates:
2219
open-telemetry:
2320
patterns:
2421
- "*opentelemetry*"
22+
- package-ecosystem: gradle
23+
directory: "/android"
24+
schedule:
25+
interval: weekly
26+
time: "09:00" # 9am UTC
27+
open-pull-requests-limit: 10
28+
groups:
2529
android-build-tools:
2630
patterns:
2731
- "*android*"

.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
@@ -76,10 +76,8 @@ jobs:
7676
# If the Autobuild fails above, remove it and uncomment the following three lines.
7777
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.
7878

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

8482
- name: Perform CodeQL Analysis
8583
uses: github/codeql-action/analyze@v4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Gradle Build and Compare Package
1+
name: Maven Build
22

33
on:
44
push:
@@ -20,36 +20,29 @@ jobs:
2020
with:
2121
java-version: 21
2222
distribution: 'temurin'
23-
cache: gradle
23+
cache: maven
2424
- name: Move generated sources to correct package
2525
run: .\scripts\copyFilesOnBuild.ps1 -inputPath '.\src\main\java\com\microsoft\graph\beta\generated'
2626
shell: pwsh
27-
- name: Grant Execute permission for gradlew
28-
run: chmod +x gradlew
29-
- name: Build with Gradle
30-
run: ./gradlew build
27+
- name: Build with Maven
28+
run: ./mvnw verify --no-transfer-progress
3129
- name: Upload Unit Test Results
3230
if: ${{ always() }}
3331
uses: actions/upload-artifact@v7
3432
with:
3533
name: UnitTests
3634
path: |
37-
build/reports/tests/test/**
38-
build/test-results/**
35+
target/surefire-reports/**
3936
- name: Upload a Build Artifact
4037
uses: actions/upload-artifact@v7
4138
with:
4239
name: drop
4340
path: |
44-
**/libs/*
45-
build/generated-pom.xml
46-
build/generated-pom.xml.asc
47-
build.gradle
48-
gradlew
49-
gradlew.bat
50-
settings.gradle
51-
gradle.properties
52-
**/gradle/**
41+
target/*.jar
42+
pom.xml
43+
mvnw
44+
mvnw.cmd
45+
.mvn/**
5346
scripts/**
5447
5548
build-java-8:
@@ -61,15 +54,12 @@ jobs:
6154
with:
6255
java-version: 8
6356
distribution: 'temurin'
64-
cache: gradle
65-
- name: Grant Execute permission for gradlew
66-
run: chmod +x gradlew
57+
cache: maven
6758
- name: Move generated sources to correct package
6859
run: .\scripts\copyFilesOnBuild.ps1 -inputPath '.\src\main\java\com\microsoft\graph\beta\generated'
6960
shell: pwsh
7061
- name: Build with Java 8
71-
working-directory: ./java-8
72-
run: .././gradlew -Dorg.gradle.jvmargs=-Xmx4g build
62+
run: ./mvnw compile --no-transfer-progress
7363

7464
build:
7565
needs: [build-latest-java, build-java-8]
@@ -83,19 +73,3 @@ jobs:
8373
else
8474
exit 1
8575
fi
86-
87-
dependency-submission:
88-
runs-on: ubuntu-latest
89-
if: github.event_name == 'push'
90-
permissions:
91-
contents: write
92-
steps:
93-
- uses: actions/checkout@v6
94-
- name: Set up JDK
95-
uses: actions/setup-java@v5
96-
with:
97-
java-version: 21
98-
distribution: 'temurin'
99-
cache: gradle
100-
- name: Generate and submit dependency graph
101-
uses: gradle/actions/dependency-submission@v4

.gitignore

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,18 @@
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
2932
.classpath
3033
.settings
3134

32-
# Maven
33-
/target/
3435
local.properties
3536
.idea
3637
*.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

android/build.gradle

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,16 @@ android {
7171
}
7272
}
7373

74-
apply from: "../gradle/dependencies.gradle"
74+
dependencies {
75+
implementation 'com.squareup.okhttp3:okhttp:4.12.0'
76+
implementation 'jakarta.annotation:jakarta.annotation-api:2.1.1'
77+
78+
api 'com.microsoft.graph:microsoft-graph-core:3.6.6'
79+
80+
implementation 'com.microsoft.kiota:microsoft-kiota-authentication-azure:1.9.2'
81+
implementation 'com.microsoft.kiota:microsoft-kiota-http-okHttp:1.9.2'
82+
implementation 'com.microsoft.kiota:microsoft-kiota-serialization-json:1.9.2'
83+
implementation 'com.microsoft.kiota:microsoft-kiota-serialization-text:1.9.2'
84+
implementation 'com.microsoft.kiota:microsoft-kiota-serialization-form:1.9.2'
85+
implementation 'com.microsoft.kiota:microsoft-kiota-serialization-multipart:1.9.2'
86+
}

0 commit comments

Comments
 (0)