Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gradle: fix IllegalStateException when resolving project deps #38607

Merged
merged 2 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
20 changes: 20 additions & 0 deletions integration-tests/gradle/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,26 @@
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<executions>
<execution>
<id>clean-generated-gradle-projects</id>
<phase>generate-resources</phase>
<goals>
<goal>clean</goal>
</goals>
<configuration>
<excludeDefaultDirectories>true</excludeDefaultDirectories>
<filesets>
<fileset>
<directory>target/classes</directory>
</fileset>
</filesets>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
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;
}
}
}
Loading