Skip to content

Commit 76077cb

Browse files
authored
Merge pull request quarkusio#49117 from reaver585/fix-tests-reloadability
Force reloadability of project dependencies in QuarkusApplicationModelTask
2 parents 1c167ae + 720f1f3 commit 76077cb

File tree

9 files changed

+123
-5
lines changed

9 files changed

+123
-5
lines changed

devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/tasks/QuarkusApplicationModelTask.java

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.gradle.api.artifacts.ResolvableDependencies;
3232
import org.gradle.api.artifacts.component.ComponentArtifactIdentifier;
3333
import org.gradle.api.artifacts.component.ComponentIdentifier;
34+
import org.gradle.api.artifacts.component.ProjectComponentIdentifier;
3435
import org.gradle.api.artifacts.result.DependencyResult;
3536
import org.gradle.api.artifacts.result.ResolvedArtifactResult;
3637
import org.gradle.api.artifacts.result.ResolvedComponentResult;
@@ -186,7 +187,7 @@ private static void collectDestinationDirs(Collection<SourceDir> sources, final
186187
}
187188
}
188189

189-
private static void collectDependencies(QuarkusResolvedClasspath classpath, ApplicationModelBuilder modelBuilder,
190+
private void collectDependencies(QuarkusResolvedClasspath classpath, ApplicationModelBuilder modelBuilder,
190191
WorkspaceModule.Mutable wsModule, ProjectDescriptor projectDescriptor) {
191192
final Map<ComponentIdentifier, List<QuarkusResolvedArtifact>> artifacts = classpath
192193
.resolvedArtifactsByComponentIdentifier();
@@ -195,8 +196,11 @@ private static void collectDependencies(QuarkusResolvedClasspath classpath, Appl
195196
final Set<ModuleVersionIdentifier> processedModules = new HashSet<>();
196197
classpath.getRoot().get().getDependencies().forEach(d -> {
197198
if (d instanceof ResolvedDependencyResult resolved) {
198-
final byte flags = (byte) (COLLECT_TOP_EXTENSION_RUNTIME_NODES | COLLECT_DIRECT_DEPS
199-
| COLLECT_RELOADABLE_MODULES);
199+
byte flags = (byte) (COLLECT_TOP_EXTENSION_RUNTIME_NODES | COLLECT_DIRECT_DEPS);
200+
final LaunchMode launchMode = getLaunchMode().get();
201+
if (!launchMode.equals(LaunchMode.NORMAL)) {
202+
flags |= COLLECT_RELOADABLE_MODULES;
203+
}
200204
collectDependencies(resolved, modelBuilder, artifacts, wsModule, alreadyCollectedFiles,
201205
processedModules, flags, projectDescriptor);
202206
}
@@ -311,8 +315,15 @@ private static void collectDependencies(
311315
newFlags = clearFlag(newFlags, COLLECT_RELOADABLE_MODULES);
312316
}
313317
if (isFlagOn(flags, COLLECT_RELOADABLE_MODULES)) {
314-
if (projectModule != null) {
315-
depBuilder.setFlags(DependencyFlags.RELOADABLE);
318+
// Checking whether current dependency is a project module is a temporary workaround,
319+
// that is required while projectModule for project dependencies is null (current
320+
// deficiency of this task).
321+
// That's why we set the workspace module flag explicitly via setWorkspaceModule().
322+
// Once we have projectModule set for project dependencies, we can remove this workaround.
323+
final boolean isProjectDependency = resolvedDependency.getSelected()
324+
.getId() instanceof ProjectComponentIdentifier;
325+
if (projectModule != null || isProjectDependency) {
326+
depBuilder.setReloadable().setWorkspaceModule();
316327
modelBuilder.addReloadableWorkspaceModule(artifactKey);
317328
} else {
318329
newFlags = clearFlag(newFlags, COLLECT_RELOADABLE_MODULES);
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: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
plugins {
2+
id 'java'
3+
id 'io.quarkus'
4+
}
5+
6+
repositories {
7+
mavenLocal {
8+
content {
9+
includeGroupByRegex 'io.quarkus.*'
10+
includeGroup 'org.hibernate.orm'
11+
}
12+
}
13+
mavenCentral()
14+
gradlePluginPortal()
15+
}
16+
17+
dependencies {
18+
implementation enforcedPlatform("${quarkusPlatformGroupId}:${quarkusPlatformArtifactId}:${quarkusPlatformVersion}")
19+
implementation "io.quarkus:quarkus-arc"
20+
21+
testImplementation project(":test-support")
22+
testImplementation "io.quarkus:quarkus-junit5"
23+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package com.module;
2+
3+
public record Person(String id) {
4+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.module;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import com.module.test.PersonFactory;
6+
7+
import io.quarkus.test.junit.QuarkusTest;
8+
9+
@QuarkusTest
10+
class PersonTest {
11+
12+
@Test
13+
void test() {
14+
PersonFactory.newRandomPerson();
15+
}
16+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
plugins {
13+
id 'io.quarkus' version "${quarkusPluginVersion}"
14+
}
15+
}
16+
rootProject.name = 'test-with-sidecar-module'
17+
18+
include "test-support"
19+
include "my-module"
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
plugins {
2+
id 'java-library'
3+
}
4+
5+
repositories {
6+
mavenLocal()
7+
mavenCentral()
8+
gradlePluginPortal()
9+
}
10+
11+
dependencies {
12+
implementation project(":my-module")
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.module.test;
2+
3+
import java.util.UUID;
4+
5+
import com.module.Person;
6+
7+
public class PersonFactory {
8+
9+
public static Person newRandomPerson() {
10+
return new Person(UUID.randomUUID().toString());
11+
}
12+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package io.quarkus.gradle;
2+
3+
import static org.assertj.core.api.Assertions.assertThat;
4+
5+
import java.io.File;
6+
7+
import org.junit.jupiter.api.Test;
8+
9+
// Reproduces https://github.com/quarkusio/quarkus/issues/48159
10+
public class TestWithSidecarModule extends QuarkusGradleWrapperTestBase {
11+
12+
@Test
13+
public void test() throws Exception {
14+
final File projectDir = getProjectDir("test-with-sidecar-module");
15+
final BuildResult build = runGradleWrapper(projectDir, "clean", ":my-module:test");
16+
assertThat(BuildResult.isSuccessful(build.getTasks().get(":my-module:test"))).isTrue();
17+
}
18+
}

0 commit comments

Comments
 (0)