Skip to content

Commit

Permalink
move hamcrest, micronaut-http-client and neo4j-harness dependencies t…
Browse files Browse the repository at this point in the history
…o features

instead of manually being set in dependencies.rocker.raw
remove dependencies.rocker.raw since it duplicates toSnippet()

rename RUNTIME to RUNTIME_ONLY, TEST to TEST_IMPLEMENTATION and
TEST_RUNTIME to TEST_RUNTIME_ONLY to reflect the actual Gradle scope
  • Loading branch information
jamesfredley committed Nov 11, 2024
1 parent e2186a2 commit 3647ba8
Show file tree
Hide file tree
Showing 28 changed files with 58 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -195,21 +195,21 @@ public Builder compileOnly() {
return scope(Scope.COMPILE_ONLY);
}

public Builder runtime() {
return scope(Scope.RUNTIME);
public Builder runtimeOnly() {
return scope(Scope.RUNTIME_ONLY);
}

public Builder test() {
return scope(Scope.TEST);
public Builder testImplementation() {
return scope(Scope.TEST_IMPLEMENTATION);
}

@SuppressWarnings("unused")
public Builder testCompileOnly() {
return scope(Scope.TEST_COMPILE_ONLY);
}

public Builder testRuntime() {
return scope(Scope.TEST_RUNTIME);
public Builder testRuntimeOnly() {
return scope(Scope.TEST_RUNTIME_ONLY);
}

public Builder annotationProcessor() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ public class Scope {
public static final Scope COMPILE_ONLY = new Scope(Source.MAIN, Collections.singletonList(Phase.COMPILATION));
public static final Scope CONSOLE = new Scope(Source.MAIN, Collections.singletonList(Phase.CONSOLE));
public static final Scope DEVELOPMENT_ONLY = new Scope(Source.MAIN, Collections.singletonList(Phase.DEVELOPMENT_ONLY));
public static final Scope RUNTIME = new Scope(Source.MAIN, Collections.singletonList(Phase.RUNTIME));
public static final Scope TEST = new Scope(Source.TEST, Arrays.asList(Phase.COMPILATION, Phase.RUNTIME));
public static final Scope RUNTIME_ONLY = new Scope(Source.MAIN, Collections.singletonList(Phase.RUNTIME));
public static final Scope TEST_IMPLEMENTATION = new Scope(Source.TEST, Arrays.asList(Phase.COMPILATION, Phase.RUNTIME));
public static final Scope TEST_ANNOTATION_PROCESSOR = new Scope(Source.TEST, Collections.singletonList(Phase.ANNOTATION_PROCESSING));
public static final Scope TEST_COMPILE_ONLY = new Scope(Source.TEST, Collections.singletonList(Phase.COMPILATION));
public static final Scope TEST_RUNTIME = new Scope(Source.TEST, Collections.singletonList(Phase.RUNTIME));
public static final Scope TEST_RUNTIME_ONLY = new Scope(Source.TEST, Collections.singletonList(Phase.RUNTIME));
public static final Scope OPENREWRITE = new Scope(Source.MAIN, Collections.singletonList(Phase.OPENREWRITE));
public static final Scope PROFILE = new Scope(Source.MAIN, Collections.singletonList(Phase.PROFILE));
public static final Scope CLASSPATH = new Scope(Source.BUILDSCRIPT, Collections.singletonList(Phase.BUILD));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public void apply(GeneratorContext generatorContext) {
generatorContext.addDependency(Dependency.builder()
.groupId("com.bertramlabs.plugins")
.lookupArtifactId("asset-pipeline-grails")
.runtime());
.runtimeOnly());

final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
generatorContext.addTemplate("advancedgrails_svg", new URLTemplate("grails-app/assets/images/advancedgrails.svg", classLoader.getResource("assets/images/advancedgrails.svg")));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
@import org.grails.forge.application.Project
@import org.grails.forge.build.gradle.GradleBuild
@import org.grails.forge.build.gradle.GradleDependency
@import org.grails.forge.feature.build.gradle.templates.dependency
@import org.grails.forge.feature.Features

@args (
Expand All @@ -16,15 +15,4 @@ dependencies {
@for (GradleDependency dependency : gradleBuild.getDependencies()) {
@dependency.toSnippet()
}

@if (features.contains("hamcrest")) {
@dependency.template("org.hamcrest","hamcrest", "testImplementation", null, false)
}

@if (!features.contains("micronaut-http-client")) {
@dependency.template("io.micronaut", "micronaut-http-client", "testImplementation", null, false)
}
@if (features.contains("neo4j-bolt")) {
@dependency.template("org.neo4j.test", "neo4j-harness", "testRuntimeOnly", null, false)
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,6 @@ public void apply(GeneratorContext generatorContext) {
generatorContext.addDependency(Dependency.builder()
.groupId("org.grails.plugins")
.lookupArtifactId("embedded-mongodb")
.scope(Scope.TEST_RUNTIME));
.scope(Scope.TEST_RUNTIME_ONLY));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,6 @@ public void apply(GeneratorContext generatorContext) {
generatorContext.addDependency(Dependency.builder()
.groupId("com.h2database")
.artifactId("h2")
.runtime());
.runtimeOnly());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public void apply(GeneratorContext generatorContext) {
generatorContext.addDependency(Dependency.builder()
.groupId("org.apache.tomcat")
.artifactId("tomcat-jdbc")
.runtime());
.runtimeOnly());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,6 @@ public void apply(GeneratorContext generatorContext) {
generatorContext.addDependency(Dependency.builder()
.groupId("mysql")
.artifactId("mysql-connector-java")
.runtime());
.runtimeOnly());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ public void apply(GeneratorContext generatorContext) {
.groupId("org.grails.plugins")
.artifactId("neo4j")
.compile());

generatorContext.addDependency(Dependency.builder()
.groupId("org.neo4j.test")
.artifactId("neo4j-harness")
.testRuntimeOnly());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,6 @@ public void apply(GeneratorContext generatorContext) {
generatorContext.addDependency(Dependency.builder()
.groupId("org.postgresql")
.artifactId("postgresql")
.runtime());
.runtimeOnly());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,6 @@ public void apply(GeneratorContext generatorContext) {
generatorContext.addDependency(Dependency.builder()
.groupId("com.microsoft.sqlserver")
.artifactId("mssql-jdbc")
.runtime());
.runtimeOnly());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ private static Dependency.Builder testContainerTestDependency(@NonNull String ar
return Dependency.builder()
.groupId(TESTCONTAINERS_GROUP_ID)
.artifactId(artifactId)
.test();
.testImplementation();
}

@NonNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void apply(GeneratorContext generatorContext) {
generatorContext.addDependency(Dependency.builder()
.groupId("org.grails.plugins")
.lookupArtifactId("grails-console")
.runtime());
.runtimeOnly());

final Map<String, Object> config = generatorContext.getConfiguration();
config.put("environments.production.grails.plugin.console.enabled", false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@ public void apply(GeneratorContext generatorContext) {
generatorContext.addDependency(Dependency.builder()
.groupId("io.micronaut")
.artifactId("micronaut-inject-groovy")
.test());
.testImplementation());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,10 @@ public void apply(GeneratorContext generatorContext) {
.groupId("io.micronaut")
.artifactId("micronaut-http-client")
.compile());

generatorContext.addDependency(Dependency.builder()
.groupId("io.micronaut")
.artifactId("micronaut-http-client")
.testImplementation());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void apply(GeneratorContext generatorContext) {
generatorContext.addDependency(Dependency.builder()
.groupId("org.assertj")
.artifactId("assertj-core")
.test());
.testImplementation());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,27 +103,27 @@ public void apply(GeneratorContext generatorContext) {
generatorContext.addDependency(Dependency.builder()
.groupId("org.grails.plugins")
.artifactId("geb")
.test());
.testImplementation());

Stream.of("api", "support", "remote-driver")
.map(name -> "selenium-" + name)
.forEach(name -> generatorContext.addDependency(Dependency.builder()
.groupId("org.seleniumhq.selenium")
.lookupArtifactId(name)
.test()));
.testImplementation()));

generatorContext.addDependency(Dependency.builder()
.groupId("org.seleniumhq.selenium")
.lookupArtifactId("selenium-chrome-driver")
.testRuntime());
.testRuntimeOnly());
generatorContext.addDependency(Dependency.builder()
.groupId("org.seleniumhq.selenium")
.lookupArtifactId("selenium-firefox-driver")
.testRuntime());
.testRuntimeOnly());
generatorContext.addDependency(Dependency.builder()
.groupId("org.seleniumhq.selenium")
.lookupArtifactId("selenium-safari-driver")
.testRuntime());
.testRuntimeOnly());

TestFramework testFramework = generatorContext.getTestFramework();
String integrationTestSourcePath = generatorContext.getIntegrationTestSourcePath("/{packagePath}/{className}");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@ public void apply(GeneratorContext generatorContext) {
generatorContext.addDependency(Dependency.builder()
.groupId("org.grails")
.artifactId("grails-gorm-testing-support")
.test());
.testImplementation());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@ public void apply(GeneratorContext generatorContext) {
generatorContext.addDependency(Dependency.builder()
.groupId("org.grails")
.artifactId("grails-web-testing-support")
.test());
.testImplementation());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

import jakarta.inject.Singleton;
import org.grails.forge.application.ApplicationType;
import org.grails.forge.application.generator.GeneratorContext;
import org.grails.forge.build.dependencies.Dependency;
import org.grails.forge.feature.Category;
import org.grails.forge.feature.Feature;

Expand Down Expand Up @@ -52,4 +54,12 @@ public String getCategory() {
public String getThirdPartyDocumentation() {
return "https://hamcrest.org/JavaHamcrest/";
}

@Override
public void apply(GeneratorContext generatorContext) {
generatorContext.addDependency(Dependency.builder()
.groupId("org.hamcrest")
.artifactId("hamcrest")
.testImplementation());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void doApply(GeneratorContext generatorContext) {
generatorContext.addDependency(Dependency.builder()
.groupId("org.junit.jupiter")
.lookupArtifactId("junit-jupiter")
.test());
.testImplementation());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,6 @@ public void apply(GeneratorContext generatorContext) {
generatorContext.addDependency(Dependency.builder()
.groupId("org.mockito")
.artifactId("mockito-core")
.test());
.testImplementation());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void doApply(GeneratorContext generatorContext) {
generatorContext.addDependency(Dependency.builder()
.groupId("org.spockframework")
.artifactId("spock-core")
.test()
.testImplementation()
.build());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@ public void apply(GeneratorContext generatorContext) {
generatorContext.addDependency(Dependency.builder()
.groupId("org.grails")
.artifactId("views-json-testing-support")
.test());
.testImplementation());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public void apply(GeneratorContext generatorContext) {
generatorContext.addDependency(Dependency.builder()
.groupId("org.fusesource.jansi")
.lookupArtifactId("jansi")
.runtime());
.runtimeOnly());

generatorContext.addDependency(Dependency.builder()
.groupId("org.grails.plugins")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public void apply(GeneratorContext generatorContext) {
generatorContext.addDependency(Dependency.builder()
.groupId("org.grails")
.artifactId("views-json-testing-support")
.test());
.testImplementation());

generatorContext.addTemplate("application_index_gson", new RockerTemplate(getViewFolderPath() + "application/index.gson", index.template()));
generatorContext.addTemplate("_errors_gson", new RockerTemplate(getViewFolderPath() + "errors/_errors.gson", _errors.template()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package org.grails.forge.build.dependencies

import org.grails.forge.application.generator.GeneratorContext
import org.grails.forge.build.gradle.GradleDependency
import org.grails.forge.options.Language
import org.grails.forge.options.TestFramework
import spock.lang.Specification

Expand All @@ -22,11 +21,11 @@ class GradleDependencyComparatorSpec extends Specification {
dep(Dependency.builder().groupId("io.micronaut.openapi").artifactId("micronaut-openapi").annotationProcessor(), ctx),
dep(Dependency.builder().groupId("io.micronaut.sql").artifactId("micronaut-jdbc-hikari").compile(), ctx),
dep(Dependency.builder().groupId("org.grails").artifactId("grails-console").console(), ctx),
dep(Dependency.builder().groupId("org.testcontainers").artifactId("testcontainers").test(), ctx),
dep(Dependency.builder().groupId("mysql").artifactId("mysql-connector-java").runtime(), ctx),
dep(Dependency.builder().groupId("org.testcontainers").artifactId("junit-jupiter").test(), ctx),
dep(Dependency.builder().groupId("org.testcontainers").artifactId("mysql").test(), ctx),
dep(Dependency.builder().groupId("ch.qos.logback").artifactId("logback-classic").runtime(), ctx)]
dep(Dependency.builder().groupId("org.testcontainers").artifactId("testcontainers").testImplementation(), ctx),
dep(Dependency.builder().groupId("mysql").artifactId("mysql-connector-java").runtimeOnly(), ctx),
dep(Dependency.builder().groupId("org.testcontainers").artifactId("junit-jupiter").testImplementation(), ctx),
dep(Dependency.builder().groupId("org.testcontainers").artifactId("mysql").testImplementation(), ctx),
dep(Dependency.builder().groupId("ch.qos.logback").artifactId("logback-classic").runtimeOnly(), ctx)]

when:
dependencies.sort(GradleDependency.COMPARATOR)
Expand Down

0 comments on commit 3647ba8

Please sign in to comment.