Skip to content

Commit 18c4887

Browse files
Merge pull request #2613 from microsoftgraph/ramsessanchez/gradle-to-maven-migration
Migrate build infrastructure from Gradle to Maven
2 parents aa92a26 + e3293a2 commit 18c4887

26 files changed

Lines changed: 912 additions & 845 deletions

.azure-pipelines/ci-build.yml

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

67-
- script: ./gradlew --no-daemon publishToMavenLocal -PmavenCentralPublishingEnabled=true
108+
- script: ./mvnw install -Psigning --no-transfer-progress
68109
displayName: Publish to local Maven for verification
69110
condition: not(contains(variables['build.sourceBranch'], 'refs/tags/v'))
70111

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

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

79120
- pwsh: |
80-
$contents = Get-Content gradle.properties -Raw
81-
$major = $contents | Select-String -Pattern 'mavenMajorVersion\s*=\s*([0-9]+)' | ForEach-Object { $_.Matches.Groups[1].Value }
82-
$minor = $contents | Select-String -Pattern 'mavenMinorVersion\s*=\s*([0-9]+)' | ForEach-Object { $_.Matches.Groups[1].Value }
83-
$patch = $contents | Select-String -Pattern 'mavenPatchVersion\s*=\s*([0-9]+)' | ForEach-Object { $_.Matches.Groups[1].Value }
121+
$pomXml = [xml](Get-Content pom.xml -Raw)
122+
$ns = New-Object System.Xml.XmlNamespaceManager($pomXml.NameTable)
123+
$ns.AddNamespace('m', $pomXml.DocumentElement.NamespaceURI)
124+
$version = $pomXml.SelectSingleNode('/m:project/m:version', $ns).InnerText
84125
$snapshot_suffix = if ($Env:BRANCH_NAME.StartsWith('refs/tags/v')) { '' } else { '-SNAPSHOT' }
85-
$version = "$major.$minor.$patch$snapshot_suffix"
126+
# If version already contains -SNAPSHOT and we're on a tag, strip it
127+
if ($Env:BRANCH_NAME.StartsWith('refs/tags/v')) {
128+
$version = $version -replace '-SNAPSHOT$', ''
129+
}
86130
echo "Current version is $version"
87131
echo "##vso[task.setvariable variable=PACKAGE_VERSION;]$version"
88132
displayName: Get current version
@@ -95,7 +139,7 @@ extends:
95139
displayName: Inspect contents of local Maven cache
96140
97141
- pwsh: |
98-
$packageFullPath = Join-Path -Path "./" -ChildPath "build/publishing-repository/com/microsoft/graph/microsoft-graph" -AdditionalChildPath "$(PACKAGE_VERSION)"
142+
$packageFullPath = Join-Path -Path "./target/staging-deploy" -ChildPath "com/microsoft/graph/microsoft-graph" -AdditionalChildPath "$(PACKAGE_VERSION)"
99143
echo "Package full path: $packageFullPath"
100144
echo "##vso[task.setvariable variable=PACKAGE_PATH;]$packageFullPath"
101145
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 & 11 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: daily
107
time: "09:00" # 9am UTC
@@ -16,12 +13,13 @@ updates:
1613
microsoft-graph:
1714
patterns:
1815
- "*microsoft-graph*"
19-
junit-dependencies:
20-
patterns:
21-
- "*junit*"
22-
open-telemetry:
23-
patterns:
24-
- "*opentelemetry*"
16+
- package-ecosystem: gradle
17+
directory: "/android"
18+
schedule:
19+
interval: daily
20+
time: "09:00" # 9am UTC
21+
open-pull-requests-limit: 10
22+
groups:
2523
android-build-tools:
2624
patterns:
2725
- "*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
@@ -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 --no-build-cache 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
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:
@@ -17,36 +17,29 @@ jobs:
1717
with:
1818
java-version: 21
1919
distribution: 'temurin'
20-
cache: gradle
20+
cache: maven
2121
- name: Move generated sources to correct package
2222
run: .\scripts\copyFilesOnBuild.ps1 -inputPath '.\src\main\java\com\microsoft\graph\generated'
2323
shell: pwsh
24-
- name: Grant Execute permission for gradlew
25-
run: chmod +x gradlew
26-
- name: Build with Gradle
27-
run: ./gradlew build
24+
- name: Build with Maven
25+
run: ./mvnw verify --no-transfer-progress
2826
- name: Upload Unit Test Results
2927
if: ${{ always() }}
3028
uses: actions/upload-artifact@v7
3129
with:
3230
name: UnitTests
3331
path: |
34-
build/reports/tests/test/**
35-
build/test-results/**
32+
target/surefire-reports/**
3633
- name: Upload a Build Artifact
3734
uses: actions/upload-artifact@v7
3835
with:
3936
name: drop
4037
path: |
41-
**/libs/*
42-
build/generated-pom.xml
43-
build/generated-pom.xml.asc
44-
build.gradle
45-
gradlew
46-
gradlew.bat
47-
settings.gradle
48-
gradle.properties
49-
**/gradle/**
38+
target/*.jar
39+
pom.xml
40+
mvnw
41+
mvnw.cmd
42+
.mvn/**
5043
scripts/**
5144
5245
build-java-8:
@@ -58,15 +51,12 @@ jobs:
5851
with:
5952
java-version: 8
6053
distribution: 'temurin'
61-
cache: gradle
54+
cache: maven
6255
- name: Move generated sources to correct package
6356
run: .\scripts\copyFilesOnBuild.ps1 -inputPath '.\src\main\java\com\microsoft\graph\generated'
6457
shell: pwsh
65-
- name: Grant Execute permission for gradlew
66-
run: chmod +x gradlew
6758
- name: Build with Java 8
68-
working-directory: ./java-8
69-
run: .././gradlew build
59+
run: ./mvnw compile --no-transfer-progress
7060

7161
build:
7262
needs: [build-java-latest, build-java-8]
@@ -81,19 +71,3 @@ jobs:
8171
exit 1
8272
fi
8373
84-
dependency-submission:
85-
runs-on: ubuntu-latest
86-
if: github.event_name == 'push'
87-
permissions:
88-
contents: write
89-
steps:
90-
- uses: actions/checkout@v6
91-
- name: Set up JDK
92-
uses: actions/setup-java@v5
93-
with:
94-
java-version: 21
95-
distribution: 'temurin'
96-
cache: gradle
97-
- name: Generate and submit dependency graph
98-
uses: gradle/actions/dependency-submission@v6
99-

.gitignore

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,17 @@
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

.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: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,17 @@ android {
7171
}
7272
}
7373

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

0 commit comments

Comments
 (0)