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

Defining a Property to Resolve Conditional Dependencies in Gradle builds #45019

Closed
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 @@ -189,20 +189,20 @@ private void registerTasks(Project project, QuarkusPluginExtension quarkusExt) {
"quarkusGenerateTestAppModel",
QuarkusApplicationModelTask.class, task -> {
configureApplicationModelTask(project, task, projectDescriptor, testClasspath, LaunchMode.TEST,
"quarkus/application-model/quarkus-app-test-model.dat");
"quarkus/application-model/quarkus-app-test-model.dat", quarkusExt.getConditionalExtensions());
});
TaskProvider<QuarkusApplicationModelTask> quarkusGenerateDevAppModelTask = tasks.register("quarkusGenerateDevAppModel",
QuarkusApplicationModelTask.class, task -> {
configureApplicationModelTask(project, task, projectDescriptor, devClasspath, LaunchMode.DEVELOPMENT,
"quarkus/application-model/quarkus-app-dev-model.dat");
"quarkus/application-model/quarkus-app-dev-model.dat", quarkusExt.getConditionalExtensions());
});

TaskProvider<QuarkusApplicationModelTask> quarkusGenerateAppModelTask = tasks.register("quarkusGenerateAppModel",
QuarkusApplicationModelTask.class, task -> {
configureApplicationModelTask(project, task, projectDescriptor
.map(d -> d.withSourceSetView(Collections.singleton(SourceSet.MAIN_SOURCE_SET_NAME))),
normalClasspath, LaunchMode.NORMAL,
"quarkus/application-model/quarkus-app-model.dat");
"quarkus/application-model/quarkus-app-model.dat", quarkusExt.getConditionalExtensions());
});

// quarkusGenerateCode
Expand Down Expand Up @@ -232,7 +232,7 @@ private void registerTasks(Project project, QuarkusPluginExtension quarkusExt) {
configureApplicationModelTask(project, task, projectDescriptor
.map(d -> d.withSourceSetView(Collections.singleton(SourceSet.MAIN_SOURCE_SET_NAME))),
normalClasspath, LaunchMode.NORMAL,
"quarkus/application-model/quarkus-app-model-build.dat");
"quarkus/application-model/quarkus-app-model-build.dat", quarkusExt.getConditionalExtensions());
});
tasks.register(QUARKUS_SHOW_EFFECTIVE_CONFIG_TASK_NAME,
QuarkusShowEffectiveConfig.class, task -> {
Expand Down Expand Up @@ -500,14 +500,16 @@ public void execute(Task task) {
private static void configureApplicationModelTask(Project project, QuarkusApplicationModelTask task,
Provider<DefaultProjectDescriptor> projectDescriptor,
ApplicationDeploymentClasspathBuilder classpath,
LaunchMode launchMode, String quarkusModelFile) {
LaunchMode launchMode, String quarkusModelFile, Property<Boolean> conditionalExtensions) {
task.getProjectDescriptor().set(projectDescriptor);
task.getLaunchMode().set(launchMode);
task.getOriginalClasspath().setFrom(classpath.getOriginalRuntimeClasspathAsInput());
task.getAppClasspath().configureFrom(classpath.getRuntimeConfigurationWithoutResolvingDeployment());
task.getPlatformConfiguration().configureFrom(classpath.getPlatformConfiguration());
task.getDeploymentClasspath().configureFrom(classpath.getDeploymentConfiguration());
task.getDeploymentResolvedWorkaround().from(classpath.getDeploymentConfiguration().getIncoming().getFiles());
if (conditionalExtensions.get()) {
task.getDeploymentResolvedWorkaround().from(classpath.getDeploymentConfiguration().getIncoming().getFiles());
}
task.getPlatformImportProperties().set(classpath.getPlatformImportsWithoutResolvingPlatform().getPlatformProperties());
task.getApplicationModel().set(project.getLayout().getBuildDirectory().file(quarkusModelFile));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public abstract class QuarkusPluginExtension extends AbstractQuarkusExtension {

private final Property<Boolean> cacheLargeArtifacts;
private final Property<Boolean> cleanupBuildOutput;
private final Property<Boolean> conditionalExtensions;

public QuarkusPluginExtension(Project project) {
super(project);
Expand All @@ -56,6 +57,8 @@ public QuarkusPluginExtension(Project project) {
.convention(true);
this.cacheLargeArtifacts = project.getObjects().property(Boolean.class)
.convention(!System.getenv().containsKey("CI"));
this.conditionalExtensions = project.getObjects().property(Boolean.class)
.convention(false);

this.sourceSetExtension = new SourceSetExtension();
}
Expand Down Expand Up @@ -130,6 +133,10 @@ public Property<Boolean> getCleanupBuildOutput() {
return cleanupBuildOutput;
}

public Property<Boolean> getConditionalExtensions() {
return conditionalExtensions;
}

public void setCleanupBuildOutput(boolean cleanupBuildOutput) {
this.cleanupBuildOutput.set(cleanupBuildOutput);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import org.gradle.api.tasks.InputFiles;
import org.gradle.api.tasks.Internal;
import org.gradle.api.tasks.Nested;
import org.gradle.api.tasks.Optional;
import org.gradle.api.tasks.OutputFile;
import org.gradle.api.tasks.SourceSet;
import org.gradle.api.tasks.TaskAction;
Expand Down Expand Up @@ -109,6 +110,7 @@ public abstract class QuarkusApplicationModelTask extends DefaultTask {
public abstract ConfigurableFileCollection getOriginalClasspath();

@InputFiles
@Optional
public abstract ConfigurableFileCollection getDeploymentResolvedWorkaround();

@Nested
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,7 @@ dependencies {
testImplementation 'io.quarkus:quarkus-junit5'
testImplementation 'io.rest-assured:rest-assured'
}

quarkus {
conditionalExtensions = true
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,7 @@ dependencies {
testImplementation 'io.quarkus:quarkus-junit5'
testImplementation 'io.rest-assured:rest-assured'
}

quarkus {
conditionalExtensions = true
}