Skip to content

Commit 4eb7644

Browse files
committed
Fix Gradle 9 compatibility issues
- Replace deprecated org.gradle.util.VersionNumber with custom version parsing in XbuildResolver.groovy (VersionNumber was removed in Gradle 7+) - Update to gradle-dotnet-plugin 3.1.0 (compatible with Gradle 9) - Replace custom Exec tasks with gradle-dotnet-plugin for better integration - Fix generateZip task to handle cases where dotnet project properties aren't available - Add JUnit Platform launcher dependency for Gradle 9+ compatibility - Configure dotnet plugin with correct workingDir and solution path
1 parent 79c8538 commit 4eb7644

File tree

2 files changed

+57
-9
lines changed

2 files changed

+57
-9
lines changed

build.gradle

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ plugins {
33
id 'com.gradle.plugin-publish' version '1.2.1' // Updated for Gradle 9 compatibility
44
id 'signing' // Required for Maven Central
55
id 'io.github.gradle-nexus.publish-plugin' version '2.0.0' // Automates Sonatype Nexus publishing
6-
id 'com.itiviti.dotnet' version '2.0.1' // MSBuild-specific: for ProjectFileParser build
6+
id 'com.itiviti.dotnet' version '3.1.0' // MSBuild-specific: for ProjectFileParser build (updated for Gradle 9)
77
id 'de.undercouch.download' version '4.1.2' // MSBuild-specific: for vswhere.exe download
88
// id 'net.researchgate.release' version '2.6.0' // Temporarily disabled for Gradle 9 compatibility
99
}
@@ -44,22 +44,43 @@ dependencies {
4444
// JUnit 5 for JUnit Platform tests (if any)
4545
testImplementation(platform('org.junit:junit-bom:5.10.1'))
4646
testImplementation('org.junit.jupiter:junit-jupiter')
47+
testRuntimeOnly('org.junit.platform:junit-platform-launcher') // Required for Gradle 9+
4748
}
4849

4950
test {
5051
useJUnitPlatform()
5152
}
5253

54+
// MSBuild-specific: .NET project build configuration using gradle-dotnet-plugin
5355
dotnet {
56+
workingDir = projectDir // Solution is at project root
5457
solution = 'ProjectFileParser.sln'
55-
projectName = 'ProjectFileParser'
58+
configuration = 'Release'
59+
restore {
60+
beforeBuild = true // Delay restore until build to avoid evaluation phase issues
61+
}
5662
}
5763

5864
tasks.test.dependsOn(tasks.named('dotnetTest'))
5965

6066
tasks.register('generateZip', Zip) {
61-
dependsOn tasks.named('dotnetBuild')
62-
from { dotnet.mainProject.properties.TargetDir } {
67+
description = 'Package .NET build output into zip'
68+
dependsOn 'dotnetBuild'
69+
// Use the dotnet plugin's mainProject properties if available, otherwise use default location
70+
from {
71+
try {
72+
def mainProject = project.dotnet?.mainProject
73+
if (mainProject?.properties?.TargetDir != null) {
74+
file(mainProject.properties.TargetDir)
75+
} else {
76+
// Fallback to default output location based on solution structure
77+
file("src/main/dotnet/ProjectFileParser/bin/Release/net6.0")
78+
}
79+
} catch (Exception e) {
80+
// If dotnet project properties aren't available, use default location
81+
file("src/main/dotnet/ProjectFileParser/bin/Release/net6.0")
82+
}
83+
} {
6384
include '*.exe'
6485
include '*.json'
6586
include '*.dll'

src/main/groovy/com/ullink/XbuildResolver.groovy

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.ullink
22

33
import org.gradle.api.GradleException
4-
import org.gradle.util.VersionNumber
54

65
class XbuildResolver implements IExecutableResolver {
76

@@ -55,7 +54,7 @@ class XbuildResolver implements IExecutableResolver {
5554
]}
5655
.findAll { it[0].exists() }
5756

58-
def foundXBuild = existingXBuilds.find { msbuild.version == null || msbuild.version.equals("${it[1].major}.${it[1].minor}".toString()) }
57+
def foundXBuild = existingXBuilds.find { msbuild.version == null || msbuild.version.equals("${it[1][0]}.${it[1][1]}".toString()) }
5958
if (foundXBuild != null) {
6059
File file = foundXBuild[0]
6160
msbuild.logger.info("Resolved xbuild to: ${file.absolutePath}")
@@ -77,9 +76,37 @@ class XbuildResolver implements IExecutableResolver {
7776
}
7877
return file.listFiles()
7978
.findAll { it.isDirectory() }
80-
.collect { [it.absolutePath, VersionNumber.parse(it.name)] }
81-
.findAll { !VersionNumber.UNKNOWN.equals(it[1]) }
82-
.sort { a, b -> b[1].compareTo(a[1]) }
79+
.collect { [it.absolutePath, parseVersion(it.name)] }
80+
.findAll { it[1] != null }
81+
.sort { a, b -> compareVersions(b[1], a[1]) }
82+
}
83+
84+
// Simple version parsing to replace org.gradle.util.VersionNumber (removed in Gradle 7+)
85+
private static List<Integer> parseVersion(String versionString) {
86+
try {
87+
def parts = versionString.split('\\.')
88+
def major = parts.length > 0 ? Integer.parseInt(parts[0]) : 0
89+
def minor = parts.length > 1 ? Integer.parseInt(parts[1]) : 0
90+
def micro = parts.length > 2 ? Integer.parseInt(parts[2]) : 0
91+
return [major, minor, micro]
92+
} catch (NumberFormatException e) {
93+
return null // Invalid version string
94+
}
95+
}
96+
97+
// Compare two version arrays [major, minor, micro]
98+
private static int compareVersions(List<Integer> v1, List<Integer> v2) {
99+
if (v1 == null && v2 == null) return 0
100+
if (v1 == null) return -1
101+
if (v2 == null) return 1
102+
103+
for (int i = 0; i < Math.max(v1.size(), v2.size()); i++) {
104+
def part1 = i < v1.size() ? v1[i] : 0
105+
def part2 = i < v2.size() ? v2[i] : 0
106+
def cmp = part1 <=> part2
107+
if (cmp != 0) return cmp
108+
}
109+
return 0
83110
}
84111

85112

0 commit comments

Comments
 (0)