Skip to content

Commit d291b4e

Browse files
snazygsmet
authored andcommitted
Gradle: fix IllegalStateException when resolving project deps
Fixes a regression from #37938 (cherry picked from commit 9a86f02)
1 parent b8dd52a commit d291b4e

File tree

12 files changed

+267
-6
lines changed

12 files changed

+267
-6
lines changed

devtools/gradle/gradle-model/src/main/java/io/quarkus/gradle/tooling/ToolingUtils.java

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,16 @@ public static Project findIncludedProject(Project project, ExternalModuleDepende
108108
}
109109
}
110110

111-
final Gradle parentGradle = project.getRootProject().getGradle().getParent();
112-
if (parentGradle != null) {
113-
return findIncludedProject(parentGradle.getRootProject(), dependency);
114-
} else {
111+
try {
112+
final Gradle parentGradle = project.getRootProject().getGradle().getParent();
113+
if (parentGradle != null) {
114+
return findIncludedProject(parentGradle.getRootProject(), dependency);
115+
} else {
116+
return null;
117+
}
118+
} catch (IllegalStateException ise) {
119+
// This can happen if the project itself is in an included build, which means that the root-project
120+
// is not yet known, so `DefaultGradle.getRootProject()` throws an ISE.
115121
return null;
116122
}
117123
}
@@ -134,9 +140,15 @@ private static Project findIncludedBuildProject(IncludedBuild ib, ExternalModule
134140
}
135141

136142
final DefaultIncludedBuild.IncludedBuildImpl dib = (DefaultIncludedBuild.IncludedBuildImpl) ib;
137-
final Project rootProject = dib.getTarget().getMutableModel().getRootProject();
143+
try {
144+
final Project rootProject = dib.getTarget().getMutableModel().getRootProject();
138145

139-
return findLocalProject(rootProject, dependency);
146+
return findLocalProject(rootProject, dependency);
147+
} catch (IllegalStateException ise) {
148+
// This can happen if the project itself is in an included build, which means that the root-project
149+
// is not yet known, so `DefaultGradle.getRootProject()` throws an ISE.
150+
return null;
151+
}
140152
}
141153

142154
public static Path serializeAppModel(ApplicationModel appModel, Task context, boolean test) throws IOException {
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Reproducer for https://github.com/quarkusio/quarkus/pull/38607: IllegalStateException when resolving project deps
2+
Test class: io.quarkus.gradle.IncludedQuarkusBuildTest
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
buildscript {
2+
repositories {
3+
mavenLocal {
4+
content {
5+
includeGroupByRegex 'io.quarkus.*'
6+
includeGroup 'org.hibernate.orm'
7+
}
8+
}
9+
mavenCentral()
10+
gradlePluginPortal()
11+
}
12+
}
13+
14+
apply plugin: 'java'
15+
16+
group = 'com.quarkus.demo'
17+
version = '1.0'
18+
19+
20+
subprojects {
21+
22+
apply plugin: 'java'
23+
group = 'com.quarkus.demo'
24+
25+
test {
26+
dependsOn 'cleanTest'
27+
useJUnitPlatform()
28+
forkEvery 1
29+
systemProperty "java.util.logging.manager", "org.jboss.logmanager.LogManager"
30+
}
31+
32+
repositories {
33+
mavenLocal {
34+
content {
35+
includeGroupByRegex 'io.quarkus.*'
36+
includeGroup 'org.hibernate.orm'
37+
}
38+
}
39+
mavenCentral()
40+
}
41+
42+
dependencies {
43+
implementation enforcedPlatform("${quarkusPlatformGroupId}:${quarkusPlatformArtifactId}:${quarkusPlatformVersion}")
44+
}
45+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
plugins {
2+
id 'java-library'
3+
}
4+
5+
dependencies {
6+
implementation("com.quarkus.includedbuild:included-quarkus:1.0")
7+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
quarkusPlatformArtifactId=quarkus-bom
2+
quarkusPlatformGroupId=io.quarkus
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
buildscript {
2+
repositories {
3+
mavenLocal {
4+
content {
5+
includeGroupByRegex 'io.quarkus.*'
6+
includeGroup 'org.hibernate.orm'
7+
}
8+
}
9+
mavenCentral()
10+
gradlePluginPortal()
11+
}
12+
}
13+
14+
apply plugin: 'java'
15+
16+
group = 'com.quarkus.directinclude'
17+
version = '1.0'
18+
19+
20+
subprojects {
21+
22+
apply plugin: 'java'
23+
group = 'com.quarkus.directinclude'
24+
25+
test {
26+
dependsOn 'cleanTest'
27+
useJUnitPlatform()
28+
forkEvery 1
29+
systemProperty "java.util.logging.manager", "org.jboss.logmanager.LogManager"
30+
}
31+
32+
repositories {
33+
mavenLocal {
34+
content {
35+
includeGroupByRegex 'io.quarkus.*'
36+
includeGroup 'org.hibernate.orm'
37+
}
38+
}
39+
mavenCentral()
40+
}
41+
42+
dependencies {
43+
implementation enforcedPlatform("${quarkusPlatformGroupId}:${quarkusPlatformArtifactId}:${quarkusPlatformVersion}")
44+
}
45+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
buildscript {
2+
repositories {
3+
mavenLocal {
4+
content {
5+
includeGroupByRegex 'io.quarkus.*'
6+
includeGroup 'org.hibernate.orm'
7+
}
8+
}
9+
mavenCentral()
10+
gradlePluginPortal()
11+
}
12+
}
13+
14+
apply plugin: 'java'
15+
16+
group = 'com.quarkus.includedbuild'
17+
version = '1.0'
18+
19+
20+
subprojects {
21+
22+
apply plugin: 'java'
23+
group = 'com.quarkus.includedbuild'
24+
25+
test {
26+
dependsOn 'cleanTest'
27+
useJUnitPlatform()
28+
forkEvery 1
29+
systemProperty "java.util.logging.manager", "org.jboss.logmanager.LogManager"
30+
}
31+
32+
repositories {
33+
mavenLocal {
34+
content {
35+
includeGroupByRegex 'io.quarkus.*'
36+
includeGroup 'org.hibernate.orm'
37+
}
38+
}
39+
mavenCentral()
40+
}
41+
42+
dependencies {
43+
implementation enforcedPlatform("${quarkusPlatformGroupId}:${quarkusPlatformArtifactId}:${quarkusPlatformVersion}")
44+
}
45+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
plugins {
2+
id 'java-library'
3+
id 'io.quarkus'
4+
}
5+
6+
dependencies {
7+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
pluginManagement {
2+
repositories {
3+
mavenLocal {
4+
content {
5+
includeGroupByRegex 'io.quarkus.*'
6+
includeGroup 'org.hibernate.orm'
7+
}
8+
}
9+
mavenCentral()
10+
gradlePluginPortal()
11+
}
12+
//noinspection GroovyAssignabilityCheck
13+
plugins {
14+
id 'io.quarkus' version "${quarkusPluginVersion}"
15+
}
16+
}
17+
18+
rootProject.name = 'nested'
19+
20+
include ':included-quarkus'
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
pluginManagement {
2+
repositories {
3+
mavenLocal {
4+
content {
5+
includeGroupByRegex 'io.quarkus.*'
6+
includeGroup 'org.hibernate.orm'
7+
}
8+
}
9+
mavenCentral()
10+
gradlePluginPortal()
11+
}
12+
//noinspection GroovyAssignabilityCheck
13+
plugins {
14+
id 'io.quarkus' version "${quarkusPluginVersion}"
15+
}
16+
}
17+
18+
includeBuild 'nested'
19+
20+
rootProject.name = 'included'
21+
22+
include ':dependency'
23+
include ':included-quarkus'

0 commit comments

Comments
 (0)