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

Externalize Gradle model builder in a module #20709

Merged
merged 1 commit into from
Oct 15, 2021
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
2 changes: 2 additions & 0 deletions devtools/gradle/gradle-application-plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ dependencies {
implementation "io.quarkus:quarkus-devtools-common:${version}"
implementation "io.quarkus:quarkus-core-deployment:${version}"

implementation project(":gradle-model")

testImplementation "io.quarkus:quarkus-project-core-extension-codestarts:${version}"
testImplementation "io.quarkus:quarkus-devmode-test-utils:${version}"
testImplementation "io.quarkus:quarkus-devtools-testing:${version}"
Expand Down
6 changes: 4 additions & 2 deletions devtools/gradle/gradle-application-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@
</parent>
<modelVersion>4.0.0</modelVersion>


<artifactId>io.quarkus.gradle.plugin</artifactId>
<packaging>pom</packaging>
<name>Quarkus - Gradle Plugin</name>
<description>Quarkus - Gradle Plugin</description>

<dependencies>
<!-- Compile -->
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-gradle-model</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-bootstrap-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import org.gradle.tooling.provider.model.ToolingModelBuilderRegistry;
import org.gradle.util.GradleVersion;

import io.quarkus.gradle.builder.GradleApplicationModelBuilder;
import io.quarkus.gradle.dependency.ApplicationDeploymentClasspathBuilder;
import io.quarkus.gradle.dependency.ConditionalDependenciesEnabler;
import io.quarkus.gradle.dependency.ExtensionDependency;
Expand All @@ -48,6 +47,7 @@
import io.quarkus.gradle.tasks.QuarkusTest;
import io.quarkus.gradle.tasks.QuarkusTestConfig;
import io.quarkus.gradle.tasks.QuarkusTestNative;
import io.quarkus.gradle.tooling.GradleApplicationModelBuilder;

public class QuarkusPlugin implements Plugin<Project> {

Expand All @@ -67,7 +67,6 @@ public class QuarkusPlugin implements Plugin<Project> {
public static final String QUARKUS_REMOTE_DEV_TASK_NAME = "quarkusRemoteDev";
public static final String QUARKUS_TEST_TASK_NAME = "quarkusTest";
public static final String DEV_MODE_CONFIGURATION_NAME = "quarkusDev";
public static final String ANNOTATION_PROCESSOR_CONFIGURATION_NAME = "quarkusAnnotationProcessor";

@Deprecated
public static final String BUILD_NATIVE_TASK_NAME = "buildNative";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
import io.quarkus.bootstrap.model.gradle.impl.ModelParameterImpl;
import io.quarkus.bootstrap.resolver.AppModelResolver;
import io.quarkus.gradle.AppModelGradleResolver;
import io.quarkus.gradle.builder.GradleApplicationModelBuilder;
import io.quarkus.gradle.tasks.QuarkusGradleUtils;
import io.quarkus.gradle.tooling.GradleApplicationModelBuilder;
import io.quarkus.runtime.LaunchMode;

public class QuarkusPluginExtension {
Expand Down
4 changes: 4 additions & 0 deletions devtools/gradle/gradle-model/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
dependencies {
implementation "io.quarkus:quarkus-core-deployment:${version}"
testImplementation "io.quarkus:quarkus-devtools-testing:${version}"
}
98 changes: 98 additions & 0 deletions devtools/gradle/gradle-model/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>io.quarkus</groupId>
<artifactId>io.quarkus.gradle.plugin.parent</artifactId>
<version>999-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

<groupId>io.quarkus</groupId>
<artifactId>quarkus-gradle-model</artifactId>
<packaging>pom</packaging>
<name>Quarkus - Gradle Model</name>
<description>Quarkus - Gradle Model</description>

<dependencies>
<!-- Compile -->
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-core-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-devtools-testing</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<id>gradle</id>
<phase>prepare-package</phase>
<configuration>
<executable>${gradle.executable}</executable>
<arguments>
<argument>clean</argument>
<argument>${gradle.task}</argument>
<argument>-Pdescription=${project.description}</argument>
<argument>-Dmaven.repo.local=${settings.localRepository}</argument>
<argument>-S</argument>
<argument>--stacktrace</argument>
<argument>--no-daemon</argument>
</arguments>
<environmentVariables>
<MAVEN_REPO_LOCAL>${settings.localRepository}</MAVEN_REPO_LOCAL>
<GRADLE_OPTS>${env.MAVEN_OPTS}</GRADLE_OPTS>
</environmentVariables>
<skip>${skip.gradle.build}</skip>
</configuration>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>attach-artifacts</id>
<phase>package</phase>
<goals>
<goal>attach-artifact</goal>
</goals>
<configuration>
<artifacts>
<artifact>
<file>build/libs/gradle-model-${project.version}.jar</file>
<type>jar</type>
</artifact>
<artifact>
<file>build/libs/gradle-model-${project.version}-javadoc.jar</file>
<type>jar</type>
<classifier>javadoc</classifier>
</artifact>
<artifact>
<file>build/libs/gradle-model-${project.version}-sources.jar</file>
<type>jar</type>
<classifier>sources</classifier>
</artifact>
</artifacts>
<skipAttach>${skip.gradle.build}</skipAttach>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.quarkus.gradle.builder;
package io.quarkus.gradle.tooling;

import java.io.BufferedReader;
import java.io.File;
Expand Down Expand Up @@ -49,9 +49,6 @@
import io.quarkus.bootstrap.workspace.DefaultProcessedSources;
import io.quarkus.bootstrap.workspace.DefaultWorkspaceModule;
import io.quarkus.bootstrap.workspace.ProcessedSources;
import io.quarkus.gradle.QuarkusPlugin;
import io.quarkus.gradle.dependency.ApplicationDeploymentClasspathBuilder;
import io.quarkus.gradle.dependency.DependencyUtils;
import io.quarkus.maven.dependency.ArtifactCoords;
import io.quarkus.maven.dependency.ArtifactKey;
import io.quarkus.maven.dependency.GACT;
Expand Down Expand Up @@ -82,7 +79,7 @@ private static Configuration classpathConfig(Project project, LaunchMode mode) {
}

return project.getConfigurations().create(CLASSPATH_CONFIGURATION).extendsFrom(
project.getConfigurations().getByName(QuarkusPlugin.DEV_MODE_CONFIGURATION_NAME),
project.getConfigurations().getByName(ToolingUtils.DEV_MODE_CONFIGURATION_NAME),
project.getConfigurations().getByName(JavaPlugin.COMPILE_CLASSPATH_CONFIGURATION_NAME),
project.getConfigurations().getByName(JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME));
}
Expand All @@ -99,24 +96,24 @@ private static Configuration deploymentClasspathConfig(Project project, LaunchMo

deploymentConfiguration = project.getConfigurations().create(DEPLOYMENT_CONFIGURATION)
.withDependencies(ds -> ds.addAll(platforms));
Configuration implementationDeployment = project.getConfigurations().findByName(ApplicationDeploymentClasspathBuilder
Configuration implementationDeployment = project.getConfigurations().findByName(ToolingUtils
.toDeploymentConfigurationName(JavaPlugin.IMPLEMENTATION_CONFIGURATION_NAME));
if (implementationDeployment != null) {
deploymentConfiguration.extendsFrom(implementationDeployment);
}

if (LaunchMode.TEST.equals(mode)) {
Configuration testDeploymentConfiguration = project.getConfigurations()
.findByName(ApplicationDeploymentClasspathBuilder
.findByName(ToolingUtils
.toDeploymentConfigurationName(JavaPlugin.TEST_IMPLEMENTATION_CONFIGURATION_NAME));
if (testDeploymentConfiguration != null) {
deploymentConfiguration.extendsFrom(testDeploymentConfiguration);
}
}
if (LaunchMode.DEVELOPMENT.equals(mode)) {
Configuration devDeploymentConfiguration = project.getConfigurations()
.findByName(ApplicationDeploymentClasspathBuilder
.toDeploymentConfigurationName(QuarkusPlugin.DEV_MODE_CONFIGURATION_NAME));
.findByName(ToolingUtils
.toDeploymentConfigurationName(ToolingUtils.DEV_MODE_CONFIGURATION_NAME));
if (devDeploymentConfiguration != null) {
deploymentConfiguration.extendsFrom(devDeploymentConfiguration);
}
Expand Down Expand Up @@ -146,7 +143,7 @@ public Object buildAll(String modelName, Project project) {
public Object buildAll(String modelName, ModelParameter parameter, Project project) {
final LaunchMode mode = LaunchMode.valueOf(parameter.getMode());

final List<org.gradle.api.artifacts.Dependency> deploymentDeps = DependencyUtils.getEnforcedPlatforms(project);
final List<org.gradle.api.artifacts.Dependency> deploymentDeps = ToolingUtils.getEnforcedPlatforms(project);
final PlatformImports platformImports = resolvePlatformImports(project, deploymentDeps);

final ResolvedDependency appArtifact = getProjectArtifact(project, mode);
Expand Down Expand Up @@ -383,7 +380,7 @@ private void collectDependencies(org.gradle.api.artifacts.ResolvedDependency res

final String classifier = a.getClassifier();
if (classifier == null || classifier.isEmpty()) {
final IncludedBuild includedBuild = DependencyUtils.includedBuild(project.getRootProject(), a.getName());
final IncludedBuild includedBuild = ToolingUtils.includedBuild(project.getRootProject(), a.getName());
if (includedBuild != null) {
final PathList.Builder pathBuilder = PathList.builder();
addSubstitutedProject(pathBuilder, includedBuild.getProjectDir());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package io.quarkus.gradle.tooling;

import java.util.ArrayList;
import java.util.List;

import org.gradle.api.Project;
import org.gradle.api.UnknownDomainObjectException;
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.artifacts.Dependency;
import org.gradle.api.artifacts.ModuleDependency;
import org.gradle.api.attributes.Category;
import org.gradle.api.initialization.IncludedBuild;
import org.gradle.api.plugins.JavaPlugin;

public class ToolingUtils {

private static final String DEPLOYMENT_CONFIGURATION_SUFFIX = "Deployment";
public static final String DEV_MODE_CONFIGURATION_NAME = "quarkusDev";

public static String toDeploymentConfigurationName(String baseConfigurationName) {
return baseConfigurationName + DEPLOYMENT_CONFIGURATION_SUFFIX;
}

public static List<Dependency> getEnforcedPlatforms(Project project) {
final List<org.gradle.api.artifacts.Dependency> directExtension = new ArrayList<>();
final Configuration impl = project.getConfigurations()
.getByName(JavaPlugin.IMPLEMENTATION_CONFIGURATION_NAME);

for (Dependency d : impl.getAllDependencies()) {
if (!(d instanceof ModuleDependency)) {
continue;
}
final ModuleDependency module = (ModuleDependency) d;
if (isEnforcedPlatform(module)) {
directExtension.add(d);
}
}
return directExtension;
}

public static boolean isEnforcedPlatform(ModuleDependency module) {
final Category category = module.getAttributes().getAttribute(Category.CATEGORY_ATTRIBUTE);
return category != null && (Category.ENFORCED_PLATFORM.equals(category.getName())
|| Category.REGULAR_PLATFORM.equals(category.getName()));
}

public static IncludedBuild includedBuild(final Project project, final String projectName) {
try {
return project.getGradle().includedBuild(projectName);
} catch (UnknownDomainObjectException ignore) {
return null;
}
}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.quarkus.gradle.builder;
package io.quarkus.gradle.tooling;

import static org.assertj.core.api.Assertions.assertThatCode;
import static org.mockito.Mockito.mock;
Expand All @@ -9,7 +9,7 @@
import org.gradle.api.artifacts.ResolvedModuleVersion;
import org.junit.jupiter.api.Test;

public class QuarkusModelBuilderTest {
public class GradleApplicationModelBuilderTest {

@Test
void testToAppDependency() {
Expand Down
13 changes: 13 additions & 0 deletions devtools/gradle/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
</parent>
<modelVersion>4.0.0</modelVersion>

<groupId>io.quarkus</groupId>
<artifactId>io.quarkus.gradle.plugin.parent</artifactId>
<packaging>pom</packaging>
<version>999-SNAPSHOT</version>
<name>Quarkus - Gradle Plugin - Parent</name>
<description>Quarkus - Gradle Plugin</description>

Expand All @@ -22,10 +24,21 @@
</properties>

<modules>
<module>gradle-model</module>
<module>gradle-application-plugin</module>
<module>gradle-extension-plugin</module>
</modules>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-gradle-model</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</dependencyManagement>

<build>
<plugins>
<!-- Do not deploy this project-->
Expand Down
2 changes: 1 addition & 1 deletion devtools/gradle/settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ gradleEnterprise {
}

rootProject.name = 'quarkus-gradle-plugins'
include 'gradle-application-plugin', 'gradle-extension-plugin'
include 'gradle-application-plugin', 'gradle-extension-plugin', 'gradle-model'