Skip to content

Commit

Permalink
Gradle: fix IllegalStateException when resolving project deps
Browse files Browse the repository at this point in the history
Fixes a regression from #37938

(cherry picked from commit 9a86f02)
  • Loading branch information
snazy authored and gsmet committed Feb 13, 2024
1 parent b8dd52a commit d291b4e
Show file tree
Hide file tree
Showing 12 changed files with 267 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,16 @@ public static Project findIncludedProject(Project project, ExternalModuleDepende
}
}

final Gradle parentGradle = project.getRootProject().getGradle().getParent();
if (parentGradle != null) {
return findIncludedProject(parentGradle.getRootProject(), dependency);
} else {
try {
final Gradle parentGradle = project.getRootProject().getGradle().getParent();
if (parentGradle != null) {
return findIncludedProject(parentGradle.getRootProject(), dependency);
} else {
return null;
}
} catch (IllegalStateException ise) {
// This can happen if the project itself is in an included build, which means that the root-project
// is not yet known, so `DefaultGradle.getRootProject()` throws an ISE.
return null;
}
}
Expand All @@ -134,9 +140,15 @@ private static Project findIncludedBuildProject(IncludedBuild ib, ExternalModule
}

final DefaultIncludedBuild.IncludedBuildImpl dib = (DefaultIncludedBuild.IncludedBuildImpl) ib;
final Project rootProject = dib.getTarget().getMutableModel().getRootProject();
try {
final Project rootProject = dib.getTarget().getMutableModel().getRootProject();

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

public static Path serializeAppModel(ApplicationModel appModel, Task context, boolean test) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Reproducer for https://github.com/quarkusio/quarkus/pull/38607: IllegalStateException when resolving project deps
Test class: io.quarkus.gradle.IncludedQuarkusBuildTest
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
buildscript {
repositories {
mavenLocal {
content {
includeGroupByRegex 'io.quarkus.*'
includeGroup 'org.hibernate.orm'
}
}
mavenCentral()
gradlePluginPortal()
}
}

apply plugin: 'java'

group = 'com.quarkus.demo'
version = '1.0'


subprojects {

apply plugin: 'java'
group = 'com.quarkus.demo'

test {
dependsOn 'cleanTest'
useJUnitPlatform()
forkEvery 1
systemProperty "java.util.logging.manager", "org.jboss.logmanager.LogManager"
}

repositories {
mavenLocal {
content {
includeGroupByRegex 'io.quarkus.*'
includeGroup 'org.hibernate.orm'
}
}
mavenCentral()
}

dependencies {
implementation enforcedPlatform("${quarkusPlatformGroupId}:${quarkusPlatformArtifactId}:${quarkusPlatformVersion}")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
plugins {
id 'java-library'
}

dependencies {
implementation("com.quarkus.includedbuild:included-quarkus:1.0")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
quarkusPlatformArtifactId=quarkus-bom
quarkusPlatformGroupId=io.quarkus
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
buildscript {
repositories {
mavenLocal {
content {
includeGroupByRegex 'io.quarkus.*'
includeGroup 'org.hibernate.orm'
}
}
mavenCentral()
gradlePluginPortal()
}
}

apply plugin: 'java'

group = 'com.quarkus.directinclude'
version = '1.0'


subprojects {

apply plugin: 'java'
group = 'com.quarkus.directinclude'

test {
dependsOn 'cleanTest'
useJUnitPlatform()
forkEvery 1
systemProperty "java.util.logging.manager", "org.jboss.logmanager.LogManager"
}

repositories {
mavenLocal {
content {
includeGroupByRegex 'io.quarkus.*'
includeGroup 'org.hibernate.orm'
}
}
mavenCentral()
}

dependencies {
implementation enforcedPlatform("${quarkusPlatformGroupId}:${quarkusPlatformArtifactId}:${quarkusPlatformVersion}")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
buildscript {
repositories {
mavenLocal {
content {
includeGroupByRegex 'io.quarkus.*'
includeGroup 'org.hibernate.orm'
}
}
mavenCentral()
gradlePluginPortal()
}
}

apply plugin: 'java'

group = 'com.quarkus.includedbuild'
version = '1.0'


subprojects {

apply plugin: 'java'
group = 'com.quarkus.includedbuild'

test {
dependsOn 'cleanTest'
useJUnitPlatform()
forkEvery 1
systemProperty "java.util.logging.manager", "org.jboss.logmanager.LogManager"
}

repositories {
mavenLocal {
content {
includeGroupByRegex 'io.quarkus.*'
includeGroup 'org.hibernate.orm'
}
}
mavenCentral()
}

dependencies {
implementation enforcedPlatform("${quarkusPlatformGroupId}:${quarkusPlatformArtifactId}:${quarkusPlatformVersion}")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
plugins {
id 'java-library'
id 'io.quarkus'
}

dependencies {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
pluginManagement {
repositories {
mavenLocal {
content {
includeGroupByRegex 'io.quarkus.*'
includeGroup 'org.hibernate.orm'
}
}
mavenCentral()
gradlePluginPortal()
}
//noinspection GroovyAssignabilityCheck
plugins {
id 'io.quarkus' version "${quarkusPluginVersion}"
}
}

rootProject.name = 'nested'

include ':included-quarkus'
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
pluginManagement {
repositories {
mavenLocal {
content {
includeGroupByRegex 'io.quarkus.*'
includeGroup 'org.hibernate.orm'
}
}
mavenCentral()
gradlePluginPortal()
}
//noinspection GroovyAssignabilityCheck
plugins {
id 'io.quarkus' version "${quarkusPluginVersion}"
}
}

includeBuild 'nested'

rootProject.name = 'included'

include ':dependency'
include ':included-quarkus'
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
rootProject.name = 'include-quarkus-build'

includeBuild 'included'

include ':depend-on-included-build'
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package io.quarkus.gradle;

import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.stream.Stream;

import org.assertj.core.api.SoftAssertions;
import org.assertj.core.api.junit.jupiter.InjectSoftAssertions;
import org.assertj.core.api.junit.jupiter.SoftAssertionsExtension;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

/**
* Reproducer for <a href="https://github.com/quarkusio/quarkus/pull/38607">{@code IllegalStateException} when
* Quarkus project is in an <em>included</em> Gradle build</a>.
*/
@ExtendWith(SoftAssertionsExtension.class)
public class IncludedQuarkusBuildTest extends QuarkusGradleWrapperTestBase {
@InjectSoftAssertions
SoftAssertions soft;

@Test
public void test() throws Exception {

final File projectDir = getProjectDir("included-build");

Path prjDir = projectDir.toPath();
Path target1 = prjDir.resolve("included").resolve("gradle.properties");
Path target2 = prjDir.resolve("included").resolve("nested").resolve("gradle.properties");
Files.deleteIfExists(target1);
Files.deleteIfExists(target2);
Files.copy(prjDir.resolve("gradle.properties"), target1);
Files.copy(prjDir.resolve("gradle.properties"), target2);

soft.assertThat(runGradleWrapper(projectDir, "clean", "jar", "--no-build-cache").unsuccessfulTasks())
.isEmpty();

try {
soft.assertAll();
} catch (AssertionError ex) {
try (Stream<Path> files = Files.walk(prjDir)) {
files.map(Path::toString).sorted().forEach(System.err::println);
}
throw ex;
}
}
}

0 comments on commit d291b4e

Please sign in to comment.