Skip to content

Commit a5994bd

Browse files
authored
Merge pull request #424 from grails/simplify-generated-build
Simplify generated build
2 parents 8cf161f + f30d3cb commit a5994bd

File tree

101 files changed

+644
-367
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+644
-367
lines changed

grails-cli/src/test/groovy/org/grails/forge/cli/CommandSpec.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class CommandSpec extends Specification {
4747
Process executeGradleCommand(String command) {
4848
StringBuilder gradleCommand = new StringBuilder()
4949
if (spock.util.environment.OperatingSystem.current.isWindows()) {
50-
gradleCommand.append("gradlew.bat")
50+
gradleCommand.append("cmd /c gradlew.bat")
5151
} else {
5252
gradleCommand.append("./gradlew")
5353
}

grails-forge-core/src/main/java/org/grails/forge/application/generator/GeneratorContext.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017-2020 original authors
2+
* Copyright 2017-2024 original authors
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -26,6 +26,7 @@
2626
import org.grails.forge.build.dependencies.*;
2727
import org.grails.forge.feature.Feature;
2828
import org.grails.forge.feature.Features;
29+
import org.grails.forge.feature.build.gradle.GradleBuildSrc;
2930
import org.grails.forge.feature.config.ApplicationConfiguration;
3031
import org.grails.forge.feature.config.BootstrapConfiguration;
3132
import org.grails.forge.feature.config.Configuration;
@@ -318,9 +319,19 @@ public void addBuildscriptDependency(@NonNull Dependency dependency) {
318319
if (dependency.requiresLookup()) {
319320
Coordinate coordinate = coordinateResolver.resolve(dependency.getArtifactId())
320321
.orElseThrow(() -> new LookupFailedException(dependency.getArtifactId()));
321-
this.buildscriptDependencies.add(dependency.resolved(coordinate));
322+
addBuildscriptDependencyBasedOnFeatures(dependency.resolved(coordinate));
322323
} else {
324+
addBuildscriptDependencyBasedOnFeatures(dependency);
325+
}
326+
}
327+
328+
private void addBuildscriptDependencyBasedOnFeatures(@NonNull Dependency dependency) {
329+
if (getFeature(GradleBuildSrc.class).isPresent()) {
330+
// for buildSrc/build.gradle with initial scope
323331
this.buildscriptDependencies.add(dependency);
332+
} else {
333+
// for main build.gradle with classpath scope
334+
this.buildscriptDependencies.add(dependency.scope(Scope.CLASSPATH));
324335
}
325336
}
326337

grails-forge-core/src/main/java/org/grails/forge/build/dependencies/Dependency.java

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,19 @@ public Dependency resolved(Coordinate coordinate) {
119119
coordinate.isPom());
120120
}
121121

122+
public Dependency scope(Scope newScope) {
123+
return new Dependency(
124+
newScope,
125+
groupId,
126+
artifactId,
127+
version,
128+
versionProperty,
129+
requiresLookup,
130+
annotationProcessorPriority,
131+
order,
132+
pom);
133+
}
134+
122135
public boolean isAnnotationProcessorPriority() {
123136
return annotationProcessorPriority;
124137
}
@@ -166,12 +179,12 @@ public Builder scope(@NonNull Scope scope) {
166179
}
167180
}
168181

169-
public Builder buildscript() {
182+
public Builder buildSrc() {
170183
return scope(Scope.BUILD);
171184
}
172185

173-
public Builder compile() {
174-
return scope(Scope.COMPILE);
186+
public Builder implementation() {
187+
return scope(Scope.IMPLEMENTATION);
175188
}
176189

177190
public Builder console() {
@@ -182,21 +195,21 @@ public Builder compileOnly() {
182195
return scope(Scope.COMPILE_ONLY);
183196
}
184197

185-
public Builder runtime() {
186-
return scope(Scope.RUNTIME);
198+
public Builder runtimeOnly() {
199+
return scope(Scope.RUNTIME_ONLY);
187200
}
188201

189-
public Builder test() {
190-
return scope(Scope.TEST);
202+
public Builder testImplementation() {
203+
return scope(Scope.TEST_IMPLEMENTATION);
191204
}
192205

193206
@SuppressWarnings("unused")
194207
public Builder testCompileOnly() {
195208
return scope(Scope.TEST_COMPILE_ONLY);
196209
}
197210

198-
public Builder testRuntime() {
199-
return scope(Scope.TEST_RUNTIME);
211+
public Builder testRuntimeOnly() {
212+
return scope(Scope.TEST_RUNTIME_ONLY);
200213
}
201214

202215
public Builder annotationProcessor() {
@@ -207,6 +220,10 @@ public Builder profile() {
207220
return scope(Scope.PROFILE);
208221
}
209222

223+
public Builder classpath() {
224+
return scope(Scope.CLASSPATH);
225+
}
226+
210227
public Builder annotationProcessor(boolean requiresPriority) {
211228
this.annotationProcessorPriority = requiresPriority;
212229
return annotationProcessor();

grails-forge-core/src/main/java/org/grails/forge/build/dependencies/Scope.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,18 @@ public class Scope {
2626

2727
public static final Scope ANNOTATION_PROCESSOR = new Scope(Source.MAIN, Collections.singletonList(Phase.ANNOTATION_PROCESSING));
2828
public static final Scope BUILD = new Scope(Source.BUILD_SRC, Arrays.asList(Phase.BUILD));
29-
public static final Scope COMPILE = new Scope(Source.MAIN, Arrays.asList(Phase.COMPILATION, Phase.RUNTIME));
29+
public static final Scope IMPLEMENTATION = new Scope(Source.MAIN, Arrays.asList(Phase.COMPILATION, Phase.RUNTIME));
3030
public static final Scope COMPILE_ONLY = new Scope(Source.MAIN, Collections.singletonList(Phase.COMPILATION));
3131
public static final Scope CONSOLE = new Scope(Source.MAIN, Collections.singletonList(Phase.CONSOLE));
3232
public static final Scope DEVELOPMENT_ONLY = new Scope(Source.MAIN, Collections.singletonList(Phase.DEVELOPMENT_ONLY));
33-
public static final Scope RUNTIME = new Scope(Source.MAIN, Collections.singletonList(Phase.RUNTIME));
34-
public static final Scope TEST = new Scope(Source.TEST, Arrays.asList(Phase.COMPILATION, Phase.RUNTIME));
33+
public static final Scope RUNTIME_ONLY = new Scope(Source.MAIN, Collections.singletonList(Phase.RUNTIME));
34+
public static final Scope TEST_IMPLEMENTATION = new Scope(Source.TEST, Arrays.asList(Phase.COMPILATION, Phase.RUNTIME));
3535
public static final Scope TEST_ANNOTATION_PROCESSOR = new Scope(Source.TEST, Collections.singletonList(Phase.ANNOTATION_PROCESSING));
3636
public static final Scope TEST_COMPILE_ONLY = new Scope(Source.TEST, Collections.singletonList(Phase.COMPILATION));
37-
public static final Scope TEST_RUNTIME = new Scope(Source.TEST, Collections.singletonList(Phase.RUNTIME));
37+
public static final Scope TEST_RUNTIME_ONLY = new Scope(Source.TEST, Collections.singletonList(Phase.RUNTIME));
3838
public static final Scope OPENREWRITE = new Scope(Source.MAIN, Collections.singletonList(Phase.OPENREWRITE));
3939
public static final Scope PROFILE = new Scope(Source.MAIN, Collections.singletonList(Phase.PROFILE));
40+
public static final Scope CLASSPATH = new Scope(Source.BUILDSCRIPT, Collections.singletonList(Phase.BUILD));
4041

4142
@NonNull
4243
private Source source;

grails-forge-core/src/main/java/org/grails/forge/build/dependencies/Source.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017-2020 original authors
2+
* Copyright 2017-2024 original authors
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,5 +18,6 @@
1818
public enum Source {
1919
MAIN,
2020
TEST,
21-
BUILD_SRC
21+
BUILD_SRC,
22+
BUILDSCRIPT
2223
}

grails-forge-core/src/main/java/org/grails/forge/build/gradle/GradleBuild.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017-2020 original authors
2+
* Copyright 2017-2024 original authors
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -69,8 +69,18 @@ public List<GradleDependency> getDependencies() {
6969
return dependencies;
7070
}
7171

72+
@NonNull
73+
public List<GradleDependency> getBuildSrcDependencies() {
74+
return buildscriptDependencies.stream().filter(gradleDependency -> !gradleDependency.getConfiguration().equals(GradleConfiguration.CLASSPATH)).collect(Collectors.toList());
75+
}
76+
7277
@NonNull
7378
public List<GradleDependency> getBuildscriptDependencies() {
79+
return buildscriptDependencies.stream().filter(gradleDependency -> gradleDependency.getConfiguration().equals(GradleConfiguration.CLASSPATH)).collect(Collectors.toList());
80+
}
81+
82+
@NonNull
83+
public List<GradleDependency> getAllBuildscriptDependencies() {
7484
return buildscriptDependencies;
7585
}
7686

@@ -84,6 +94,16 @@ public List<GradlePlugin> getPluginsWithVersion() {
8494
return plugins.stream().filter(plugin -> plugin.getVersion() != null).collect(Collectors.toList());
8595
}
8696

97+
@NonNull
98+
public List<GradlePlugin> getPluginsWithoutApply() {
99+
return plugins.stream().filter(plugin -> !plugin.useApplyPlugin()).collect(Collectors.toList());
100+
}
101+
102+
@NonNull
103+
public List<GradlePlugin> getPluginsWithApply() {
104+
return plugins.stream().filter(plugin -> plugin.useApplyPlugin()).collect(Collectors.toList());
105+
}
106+
87107
@NonNull
88108
public String renderExtensions() {
89109
return renderWritableExtensions(Stream.concat(

grails-forge-core/src/main/java/org/grails/forge/build/gradle/GradleConfiguration.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.util.Optional;
2626

2727
public enum GradleConfiguration implements Ordered {
28+
CLASSPATH("classpath", -2),
2829
PROFILE("profile", -1),
2930
BUILD("implementation", 0),
3031
ANNOTATION_PROCESSOR("annotationProcessor", 1),
@@ -74,6 +75,11 @@ public static Optional<GradleConfiguration> of(@NonNull Scope scope,
7475
return Optional.of(GradleConfiguration.BUILD);
7576
}
7677
break;
78+
case BUILDSCRIPT:
79+
if (scope.getPhases().contains(Phase.BUILD)) {
80+
return Optional.of(GradleConfiguration.CLASSPATH);
81+
}
82+
break;
7783
case MAIN:
7884
if (scope.getPhases().contains(Phase.ANNOTATION_PROCESSING)) {
7985
return Optional.of(GradleConfiguration.COMPILE_ONLY);

grails-forge-core/src/main/java/org/grails/forge/build/gradle/GradleDependency.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017-2020 original authors
2+
* Copyright 2017-2024 original authors
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -99,13 +99,12 @@ public int hashCode() {
9999

100100
@NonNull
101101
public String toSnippet() {
102-
String snippet = gradleConfiguration.getConfigurationName();
102+
String snippet = gradleConfiguration.getConfigurationName() + " ";
103103
if (isPom()) {
104-
String platformPrefix = " ";
105-
snippet += platformPrefix + "platform";
104+
snippet += "platform(";
106105
}
107-
snippet += "(\"" + getGroupId() + ':' + getArtifactId() +
108-
(getVersion() != null ? (':' + getVersion()) : "") + "\")";
106+
snippet += "\"" + getGroupId() + ':' + getArtifactId() +
107+
(getVersion() != null ? (':' + getVersion()) : "") + "\"";
109108
if (isPom()) {
110109
snippet += ")";
111110
}

grails-forge-core/src/main/java/org/grails/forge/build/gradle/GradlePlugin.java

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017-2020 original authors
2+
* Copyright 2017-2024 original authors
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -37,6 +37,7 @@ public class GradlePlugin implements BuildPlugin {
3737
private final boolean requiresLookup;
3838
private final Set<String> buildImports;
3939
private final int order;
40+
private final boolean useApplyPlugin;
4041

4142
public GradlePlugin(@NonNull String id,
4243
@Nullable String version,
@@ -46,6 +47,26 @@ public GradlePlugin(@NonNull String id,
4647
boolean requiresLookup,
4748
int order,
4849
Set<String> buildImports) {
50+
this(id,
51+
version,
52+
artifactId,
53+
extension,
54+
settingsExtension,
55+
requiresLookup,
56+
order,
57+
buildImports,
58+
false);
59+
}
60+
61+
public GradlePlugin(@NonNull String id,
62+
@Nullable String version,
63+
@Nullable String artifactId,
64+
@Nullable Writable extension,
65+
@Nullable Writable settingsExtension,
66+
boolean requiresLookup,
67+
int order,
68+
Set<String> buildImports,
69+
boolean useApplyPlugin) {
4970
this.id = id;
5071
this.version = version;
5172
this.artifactId = artifactId;
@@ -54,6 +75,7 @@ public GradlePlugin(@NonNull String id,
5475
this.requiresLookup = requiresLookup;
5576
this.order = order;
5677
this.buildImports = buildImports;
78+
this.useApplyPlugin = useApplyPlugin;
5779
}
5880

5981
@Nullable
@@ -98,6 +120,10 @@ public boolean requiresLookup() {
98120
return requiresLookup;
99121
}
100122

123+
public boolean useApplyPlugin() {
124+
return useApplyPlugin;
125+
}
126+
101127
@Override
102128
public BuildPlugin resolved(CoordinateResolver coordinateResolver) {
103129
Coordinate coordinate = coordinateResolver.resolve(artifactId)
@@ -137,6 +163,7 @@ public static final class Builder {
137163
private boolean requiresLookup;
138164
private boolean pom = false;
139165
private int order = 0;
166+
private boolean useApplyPlugin = false;
140167
private boolean template = false;
141168
private Set<String> buildImports = new HashSet<>();
142169

@@ -199,8 +226,13 @@ public GradlePlugin.Builder pom(boolean pom) {
199226
return this;
200227
}
201228

229+
public GradlePlugin.Builder useApplyPlugin(boolean useApplyPlugin) {
230+
this.useApplyPlugin = useApplyPlugin;
231+
return this;
232+
}
233+
202234
public GradlePlugin build() {
203-
return new GradlePlugin(id, version, artifactId, extension, settingsExtension, requiresLookup, order, buildImports);
235+
return new GradlePlugin(id, version, artifactId, extension, settingsExtension, requiresLookup, order, buildImports, useApplyPlugin);
204236
}
205237

206238
private GradlePlugin.Builder copy() {

grails-forge-core/src/main/java/org/grails/forge/feature/assetPipeline/AssetPipeline.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017-2020 original authors
2+
* Copyright 2017-2024 original authors
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -60,19 +60,17 @@ public String getDescription() {
6060

6161
@Override
6262
public void apply(GeneratorContext generatorContext) {
63-
generatorContext.addBuildscriptDependency(Dependency.builder()
64-
.groupId("com.bertramlabs.plugins")
65-
.lookupArtifactId("asset-pipeline-gradle")
66-
.buildscript());
63+
6764
generatorContext.addBuildPlugin(GradlePlugin.builder()
6865
.id("com.bertramlabs.asset-pipeline")
6966
.extension(new RockerWritable(assetPipelineExtension.template(generatorContext.getApplicationType())))
67+
.lookupArtifactId("asset-pipeline-gradle")
7068
.build());
7169

7270
generatorContext.addDependency(Dependency.builder()
7371
.groupId("com.bertramlabs.plugins")
7472
.lookupArtifactId("asset-pipeline-grails")
75-
.runtime());
73+
.runtimeOnly());
7674

7775
final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
7876
generatorContext.addTemplate("advancedgrails_svg", new URLTemplate("grails-app/assets/images/advancedgrails.svg", classLoader.getResource("assets/images/advancedgrails.svg")));

0 commit comments

Comments
 (0)