Skip to content

Commit 8ad1d84

Browse files
authored
Resolve dependencies from "project" repositories, not buildscript (1 of 3) #980
2 parents f9d66c4 + 4ad0be2 commit 8ad1d84

25 files changed

+85
-86
lines changed

gradle/spotless-freshmark.gradle

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,16 @@ spotless {
4949
}
5050
}
5151

52+
def versionLast = spotlessChangelog.versionLast
53+
def versionNext = spotlessChangelog.versionNext
54+
5255
// if this freshmark has a changelog file, then it has version-sensitive content
5356
if (tasks.names.contains('changelogCheck')) {
5457
// normally we use versionLast for our freshmark
5558
spotless {
5659
freshmark {
5760
properties {
58-
it.put('versionLast', spotlessChangelog.versionLast)
61+
it.put('versionLast', versionLast)
5962
}
6063
}
6164
}
@@ -65,7 +68,7 @@ if (tasks.names.contains('changelogCheck')) {
6568
freshmarkSetup.execute(freshmark)
6669
freshmark.properties {
6770
// that uses versionNext as versionLast
68-
it.put('versionLast', spotlessChangelog.versionNext)
71+
it.put('versionLast', versionNext)
6972
}
7073
def changelogBumpFreshmark = freshmark.createIndependentApplyTask('changelogBumpFreshmark')
7174
// freshmark should run after the changelog bump

gradle/spotless.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ spotless {
88
*/
99
String regex = "import org\\.gradle\\.api\\.internal\\.(?!plugins\\.DslObject)(?!project\\.ProjectInternal)"
1010
if ((text.contains('import org.gradle.internal.') || text.find(regex)) &&
11-
!text.contains('def noInternalDepsClosure')) {
11+
!text.contains('def noInternalDepsClosure')) {
1212
throw new AssertionError("Accidental internal import")
1313
}
1414
}

plugin-gradle/CHANGES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`).
44

55
## [Unreleased]
6+
### Changed
7+
* **BREAKING** Previously, many projects required `buildscript { repositories { mavenCentral() }}` at the top of their root project, because Spotless resolved its dependencies using the buildscript repositories. Spotless now resolves its dependencies from the normal project repositories of the root project, which means that you can remove the `buildscript {}` block, but you still need `repositories { mavenCentral() }` (or similar) in the root project.
8+
* Bump minimum required Gradle from `6.1` to `6.1.1`.
69

710
## [5.17.1] - 2021-10-26
811
### Changed
@@ -44,6 +47,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
4447
* `:spotlessInternalRegisterDependencies task failed.`
4548
* `Cannot add a configuration with name 'spotless-1911100560'`
4649
* Spotless does not [yet](https://github.com/diffplug/spotless/pull/721) support configuration-cache, but now it can never interfere with configuration-cache for other tasks. ([#720](https://github.com/diffplug/spotless/pull/720))
50+
* Bump minimum required Gradle from `5.4` to `6.1`.
4751

4852
## [5.15.0] - 2021-09-04
4953
### Added

plugin-gradle/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ All the generic steps live in [`FormatExtension`](https://javadoc.io/doc/com.dif
130130

131131
### Requirements
132132

133-
Spotless requires JRE 8+, and Gradle 5.4+. Some steps require JRE 11+, `Unsupported major.minor version` means you're using a step that needs a newer JRE.
133+
Spotless requires JRE 8+, and Gradle 6.1.1+. Some steps require JRE 11+, `Unsupported major.minor version` means you're using a step that needs a newer JRE.
134134

135135
If you're stuck on an older version of Gradle, `id 'com.diffplug.gradle.spotless' version '4.5.1'` supports all the way back to Gradle 2.x`.
136136

plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GradleProvisioner.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public Set<File> provisionWithTransitives(boolean withTransitives, Collection<St
6060
if (result != null) {
6161
return result;
6262
} else {
63-
result = GradleProvisioner.fromRootBuildscript(rootProject).provisionWithTransitives(req.withTransitives, req.mavenCoords);
63+
result = GradleProvisioner.forProject(rootProject).provisionWithTransitives(req.withTransitives, req.mavenCoords);
6464
cache.put(req, result);
6565
return result;
6666
}
@@ -69,23 +69,24 @@ public Set<File> provisionWithTransitives(boolean withTransitives, Collection<St
6969
}
7070
}
7171

72-
static Provisioner fromRootBuildscript(Project project) {
72+
static Provisioner forProject(Project project) {
7373
Objects.requireNonNull(project);
7474
return (withTransitives, mavenCoords) -> {
7575
try {
76-
Configuration config = project.getRootProject().getBuildscript().getConfigurations().create("spotless"
76+
Configuration config = project.getConfigurations().create("spotless"
7777
+ new Request(withTransitives, mavenCoords).hashCode());
7878
mavenCoords.stream()
79-
.map(project.getBuildscript().getDependencies()::create)
79+
.map(project.getDependencies()::create)
8080
.forEach(config.getDependencies()::add);
8181
config.setDescription(mavenCoords.toString());
8282
config.setTransitive(withTransitives);
8383
return config.resolve();
8484
} catch (Exception e) {
85+
String projName = project.getPath();
8586
logger.log(
8687
Level.SEVERE,
87-
"You probably need to add a repository containing the '" + mavenCoords + "' artifact in the 'build.gradle' of your root project.\n" +
88-
"E.g.: 'buildscript { repositories { mavenCentral() }}'",
88+
"You probably need to add a repository containing the '" + mavenCoords + "' artifact in the 'build.gradle' of the " + projName + " project.\n" +
89+
"E.g.: 'repositories { mavenCentral() }'",
8990
e);
9091
throw e;
9192
}
@@ -125,7 +126,7 @@ public boolean equals(Object obj) {
125126
public String toString() {
126127
String coords = mavenCoords.toString();
127128
StringBuilder builder = new StringBuilder();
128-
builder.append(coords.substring(1, coords.length() - 1)); // strip off []
129+
builder.append(coords, 1, coords.length() - 1); // strip off []
129130
if (withTransitives) {
130131
builder.append(" with transitives");
131132
} else {

plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessPlugin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
public class SpotlessPlugin implements Plugin<Project> {
2626
static final String SPOTLESS_MODERN = "spotlessModern";
27-
static final String MINIMUM_GRADLE = "6.1";
27+
static final String MINIMUM_GRADLE = "6.1.1";
2828

2929
@Override
3030
public void apply(Project project) {

plugin-gradle/src/test/java/com/diffplug/gradle/spotless/Antlr4ExtensionTest.java

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,10 @@ class Antlr4ExtensionTest extends GradleIntegrationHarness {
2424
@Test
2525
void applyUsingDefaultVersion() throws IOException {
2626
String[] buildScript = {
27-
"buildscript {",
28-
" repositories {",
29-
" mavenCentral()",
30-
" }",
31-
"}",
3227
"plugins {",
3328
" id 'com.diffplug.spotless'",
3429
"}",
30+
"repositories { mavenCentral() }",
3531
"spotless {",
3632
" antlr4 {",
3733
" target 'src/main/antlr4/**/*.g4'",
@@ -45,14 +41,10 @@ void applyUsingDefaultVersion() throws IOException {
4541
@Test
4642
void applyUsingCustomVersion() throws IOException {
4743
String[] buildScript = {
48-
"buildscript {",
49-
" repositories {",
50-
" mavenCentral()",
51-
" }",
52-
"}",
5344
"plugins {",
5445
" id 'com.diffplug.spotless'",
5546
"}",
47+
"repositories { mavenCentral() }",
5648
"spotless {",
5749
" antlr4 {",
5850
" target 'src/main/antlr4/**/*.g4'",

plugin-gradle/src/test/java/com/diffplug/gradle/spotless/ConfigAvoidanceTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ class ConfigAvoidanceTest extends GradleIntegrationHarness {
2424
@Test
2525
void noConfigOnHelp() throws IOException {
2626
setFile("build.gradle").toLines(
27-
"buildscript { repositories { mavenCentral() } }",
2827
"plugins {",
2928
" id 'com.diffplug.spotless'",
3029
"}",
30+
"repositories { mavenCentral() }",
3131
"apply plugin: 'java'",
3232
"spotless {",
3333
" java {",

plugin-gradle/src/test/java/com/diffplug/gradle/spotless/ConfigurationCacheTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ protected void runTasks(String... tasks) throws IOException {
3737
@Test
3838
public void helpConfigures() throws IOException {
3939
setFile("build.gradle").toLines(
40-
"buildscript { repositories { mavenCentral() } }",
4140
"plugins {",
4241
" id 'com.diffplug.spotless'",
4342
"}",
43+
"repositories { mavenCentral() }",
4444
"apply plugin: 'java'",
4545
"spotless {",
4646
" java {",
@@ -53,10 +53,10 @@ public void helpConfigures() throws IOException {
5353
@Test
5454
public void helpConfiguresIfTasksAreCreated() throws IOException {
5555
setFile("build.gradle").toLines(
56-
"buildscript { repositories { mavenCentral() } }",
5756
"plugins {",
5857
" id 'com.diffplug.spotless'",
5958
"}",
59+
"repositories { mavenCentral() }",
6060
"apply plugin: 'java'",
6161
"spotless {",
6262
" java {",

plugin-gradle/src/test/java/com/diffplug/gradle/spotless/FilePermissionsTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ class FilePermissionsTest extends GradleIntegrationHarness {
3232
@DisabledOnOs(WINDOWS)
3333
void spotlessApplyShouldPreservePermissions() throws IOException {
3434
setFile("build.gradle").toLines(
35-
"buildscript { repositories { mavenCentral() } }",
3635
"plugins {",
3736
" id 'com.diffplug.spotless'",
3837
"}",
38+
"repositories { mavenCentral() }",
3939
"",
4040
"spotless {",
4141
" java {",

0 commit comments

Comments
 (0)