Skip to content
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 @@ -31,6 +31,7 @@
import org.gradle.api.artifacts.ResolvableDependencies;
import org.gradle.api.artifacts.component.ComponentArtifactIdentifier;
import org.gradle.api.artifacts.component.ComponentIdentifier;
import org.gradle.api.artifacts.component.ProjectComponentIdentifier;
import org.gradle.api.artifacts.result.DependencyResult;
import org.gradle.api.artifacts.result.ResolvedArtifactResult;
import org.gradle.api.artifacts.result.ResolvedComponentResult;
Expand Down Expand Up @@ -186,7 +187,7 @@ private static void collectDestinationDirs(Collection<SourceDir> sources, final
}
}

private static void collectDependencies(QuarkusResolvedClasspath classpath, ApplicationModelBuilder modelBuilder,
private void collectDependencies(QuarkusResolvedClasspath classpath, ApplicationModelBuilder modelBuilder,
WorkspaceModule.Mutable wsModule, ProjectDescriptor projectDescriptor) {
final Map<ComponentIdentifier, List<QuarkusResolvedArtifact>> artifacts = classpath
.resolvedArtifactsByComponentIdentifier();
Expand All @@ -195,8 +196,11 @@ private static void collectDependencies(QuarkusResolvedClasspath classpath, Appl
final Set<ModuleVersionIdentifier> processedModules = new HashSet<>();
classpath.getRoot().get().getDependencies().forEach(d -> {
if (d instanceof ResolvedDependencyResult resolved) {
final byte flags = (byte) (COLLECT_TOP_EXTENSION_RUNTIME_NODES | COLLECT_DIRECT_DEPS
| COLLECT_RELOADABLE_MODULES);
byte flags = (byte) (COLLECT_TOP_EXTENSION_RUNTIME_NODES | COLLECT_DIRECT_DEPS);
final LaunchMode launchMode = getLaunchMode().get();
if (!launchMode.equals(LaunchMode.NORMAL)) {
flags |= COLLECT_RELOADABLE_MODULES;
}
collectDependencies(resolved, modelBuilder, artifacts, wsModule, alreadyCollectedFiles,
processedModules, flags, projectDescriptor);
}
Expand Down Expand Up @@ -311,8 +315,15 @@ private static void collectDependencies(
newFlags = clearFlag(newFlags, COLLECT_RELOADABLE_MODULES);
}
if (isFlagOn(flags, COLLECT_RELOADABLE_MODULES)) {
if (projectModule != null) {
depBuilder.setFlags(DependencyFlags.RELOADABLE);
// Checking whether current dependency is a project module is a temporary workaround,
// that is required while projectModule for project dependencies is null (current
// deficiency of this task).
// That's why we set the workspace module flag explicitly via setWorkspaceModule().
// Once we have projectModule set for project dependencies, we can remove this workaround.
final boolean isProjectDependency = resolvedDependency.getSelected()
.getId() instanceof ProjectComponentIdentifier;
if (projectModule != null || isProjectDependency) {
depBuilder.setReloadable().setWorkspaceModule();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aloubyansky please note that I added .setWorkspaceModule() here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it shouldn't be necessary. But ok, I guess.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't make it work without setting this flag - new test i added fails.
I think we need to set this flag, since it's not set elsewhere and without it, project dependency does not end up in the runtime classloader -> see 1 -> 2 -> 3

modelBuilder.addReloadableWorkspaceModule(artifactKey);
} else {
newFlags = clearFlag(newFlags, COLLECT_RELOADABLE_MODULES);
Expand Down
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,23 @@
plugins {
id 'java'
id 'io.quarkus'
}

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

dependencies {
implementation enforcedPlatform("${quarkusPlatformGroupId}:${quarkusPlatformArtifactId}:${quarkusPlatformVersion}")
implementation "io.quarkus:quarkus-arc"

testImplementation project(":test-support")
testImplementation "io.quarkus:quarkus-junit5"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.module;

public record Person(String id) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.module;

import org.junit.jupiter.api.Test;

import com.module.test.PersonFactory;

import io.quarkus.test.junit.QuarkusTest;

@QuarkusTest
class PersonTest {

@Test
void test() {
PersonFactory.newRandomPerson();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
pluginManagement {
repositories {
mavenLocal {
content {
includeGroupByRegex 'io.quarkus.*'
includeGroup 'org.hibernate.orm'
}
}
mavenCentral()
gradlePluginPortal()
}
plugins {
id 'io.quarkus' version "${quarkusPluginVersion}"
}
}
rootProject.name = 'test-with-sidecar-module'

include "test-support"
include "my-module"
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
plugins {
id 'java-library'
}

repositories {
mavenLocal()
mavenCentral()
gradlePluginPortal()
}

dependencies {
implementation project(":my-module")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.module.test;

import java.util.UUID;

import com.module.Person;

public class PersonFactory {

public static Person newRandomPerson() {
return new Person(UUID.randomUUID().toString());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package io.quarkus.gradle;

import static org.assertj.core.api.Assertions.assertThat;

import java.io.File;

import org.junit.jupiter.api.Test;

// Reproduces https://github.com/quarkusio/quarkus/issues/48159
public class TestWithSidecarModule extends QuarkusGradleWrapperTestBase {

@Test
public void test() throws Exception {
final File projectDir = getProjectDir("test-with-sidecar-module");
final BuildResult build = runGradleWrapper(projectDir, "clean", ":my-module:test");
assertThat(BuildResult.isSuccessful(build.getTasks().get(":my-module:test"))).isTrue();
}
}
Loading