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

Introduce on-the-fly generation of Gradle JARs #107

Open
wants to merge 4 commits into
base: develop-1.x
Choose a base branch
from
Open
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
@@ -0,0 +1,100 @@
package dev.gradleplugins;

import dev.gradleplugins.buildscript.io.GradleBuildFile;
import dev.gradleplugins.buildscript.io.GradleSettingsFile;
import dev.gradleplugins.runnerkit.GradleExecutor;
import dev.gradleplugins.runnerkit.GradleRunner;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.CleanupMode;
import org.junit.jupiter.api.io.TempDir;

import java.nio.file.Path;

import static dev.gradleplugins.buildscript.syntax.Syntax.groovyDsl;


class GradlePluginDevelopmentGeneratedGradleJarsFunctionalTests {
@TempDir(cleanup = CleanupMode.ON_SUCCESS) Path testDirectory;
GradleRunner runner = GradleRunner.create(GradleExecutor.gradleTestKit()).withGradleVersion(System.getProperty("dev.gradleplugins.defaultGradleVersion")).withPluginClasspath().inDirectory(() -> testDirectory);
GradleBuildFile buildFile;
GradleSettingsFile settingsFile;

@BeforeEach
void setup() {
settingsFile = GradleSettingsFile.inDirectory(testDirectory);
buildFile = GradleBuildFile.inDirectory(testDirectory);
buildFile.plugins(it -> {
it.id("dev.gradleplugins.gradle-plugin-base");
it.id("java-library");
});

buildFile.append(groovyDsl(
"Set<String> allDependencies(Configuration configuration) {",
" return configuration.incoming.resolutionResult.allDependencies.collect { result ->",
" def it = result.requested",
" if (it instanceof ModuleComponentSelector) {",
" return \"${it.group}:${it.module}:${it.version}\".toString()",
" } else if (it instanceof ProjectComponentSelector) {",
" return it.projectPath",
" } else {",
" throw new RuntimeException()",
" }",
" }",
"}"
));
}

@Nested
class GradleApiDependencyTest {
@Test
void test() {
buildFile.append(groovyDsl(
"repositories {",
" gradleDistributions()",
" mavenCentral()",
"}",
"dependencies {",
" implementation gradleApi('8.9-rc-1')",
"}",
"tasks.register('verify') {",
" doLast {",
" assert allDependencies(configurations.compileClasspath)",
" .containsAll(['dev.gradleplugins.generated:gradle-api:8.9-rc-1', 'org.codehaus.groovy:groovy:3.0.21'])",
" assert allDependencies(configurations.runtimeClasspath)",
" .containsAll(['dev.gradleplugins.generated:gradle-api:8.9-rc-1', 'org.codehaus.groovy:groovy-all:3.0.21', 'org.jetbrains.kotlin:kotlin-stdlib:1.9.23'])",
" }",
"}"
));

runner.withArgument("verify").build();
}
}

@Nested
class GradleTestKitDependencyTest {
@Test
void test() {
buildFile.append(groovyDsl(
"repositories {",
" gradleDistributions()",
" mavenCentral()",
"}",
"dependencies {",
" implementation gradleTestKit('8.9-rc-1')",
"}",
"tasks.register('verify') {",
" doLast {",
" assert allDependencies(configurations.compileClasspath)",
" .containsAll(['dev.gradleplugins.generated:gradle-test-kit:8.9-rc-1', 'org.codehaus.groovy:groovy:3.0.21'])",
" assert allDependencies(configurations.runtimeClasspath)",
" .containsAll(['dev.gradleplugins.generated:gradle-test-kit:8.9-rc-1', 'org.codehaus.groovy:groovy-all:3.0.21', 'org.jetbrains.kotlin:kotlin-stdlib:1.9.23'])",
" }",
"}"
));

runner.withArgument("verify").build();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.gradle.api.Action;
import org.gradle.api.artifacts.dsl.RepositoryHandler;
import org.gradle.api.artifacts.repositories.ArtifactRepository;
import org.gradle.api.artifacts.repositories.MavenArtifactRepository;
import org.gradle.api.plugins.ExtensionAware;

Expand All @@ -28,6 +29,20 @@ public interface GradlePluginDevelopmentRepositoryExtension {
*/
MavenArtifactRepository gradlePluginDevelopment(Action<? super MavenArtifactRepository> action);

/**
* Adds a Gradle Distributions repository containing the Gradle API/TestKit.
*
* @return the Gradle Distributions repository instance added to the repository handler.
*/
ArtifactRepository gradleDistributions();

/**
* Adds a Gradle Distributions Snapshots repository containing the Gradle API/TestKit.
*
* @return the Gradle Distributions Snapshots repository instance added to the repository handler.
*/
ArtifactRepository gradleDistributionsSnapshots();

/**
* Returns {@link RepositoryHandler} extension methods.
*
Expand Down
Loading
Loading