Skip to content

Commit

Permalink
Merge pull request #100 from cal101/master
Browse files Browse the repository at this point in the history
gradle: resolve plugin dependencies via buildscript repositories not …
  • Loading branch information
nedtwigg authored Apr 11, 2017
2 parents 5046667 + 3024972 commit dd90ab7
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 22 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ You might be looking for:
### Version 1.3.0-SNAPSHOT - TBD (javadoc [lib](https://diffplug.github.io/spotless/javadoc/spotless-lib/snapshot/) [lib-extra](https://diffplug.github.io/spotless/javadoc/spotless-lib-extra/snapshot/), [snapshot repo](https://oss.sonatype.org/content/repositories/snapshots/com/diffplug/spotless/))

* Added support for Groovy via [greclipse](https://github.com/groovy/groovy-eclipse).
* When a JarState resolution failed, it threw a Gradle-specific error message. That message has been moved out of `lib` and into `plugin-gradle` where it belongs.

### Version 1.2.0 - April 3rd 2017 (javadoc [lib](https://diffplug.github.io/spotless/javadoc/spotless-lib/1.2.0/) [lib-extra](https://diffplug.github.io/spotless/javadoc/spotless-lib-extra/1.2.0/), artifact [lib]([jcenter](https://bintray.com/diffplug/opensource/spotless-lib), [lib-extra]([jcenter](https://bintray.com/diffplug/opensource/spotless-lib-extra)))

Expand Down
15 changes: 3 additions & 12 deletions lib/src/main/java/com/diffplug/spotless/JarState.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

Expand All @@ -37,7 +35,6 @@
*/
public final class JarState implements Serializable {
private static final long serialVersionUID = 1L;
private static final Logger logger = Logger.getLogger(JarState.class.getName());

@SuppressWarnings("unused")
private final String mavenCoordinate;
Expand All @@ -60,15 +57,9 @@ public JarState(String mavenCoordinate, FileSignature fileSignature, Set<File> j

public static JarState from(String mavenCoordinate, Provisioner provisioner) throws IOException {
Objects.requireNonNull(mavenCoordinate);
Set<File> jars;
try {
jars = provisioner.provisionWithDependencies(mavenCoordinate);
if (jars.isEmpty()) {
throw new NoSuchElementException("Resolved to an empty result.");
}
} catch (Exception e) {
logger.log(Level.SEVERE, "You probably need to add a repository containing the `" + mavenCoordinate + "` artifact to your buildscript, e.g.: repositories { mavenCentral() }", e);
throw e;
Set<File> jars = provisioner.provisionWithDependencies(mavenCoordinate);
if (jars.isEmpty()) {
throw new NoSuchElementException("Resolved to an empty result: " + mavenCoordinate);
}
FileSignature fileSignature = FileSignature.signAsSet(jars);
return new JarState(mavenCoordinate, fileSignature, jars);
Expand Down
1 change: 1 addition & 0 deletions plugin-gradle/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### Version 3.3.0-SNAPSHOT - TBD ([javadoc](https://diffplug.github.io/spotless/javadoc/snapshot/), [snapshot](https://oss.sonatype.org/content/repositories/snapshots/com/diffplug/spotless/spotless-plugin-gradle/))

* Added support for groovy formatting (huge thanks to Frank Vennemeyer! [#94](https://github.com/diffplug/spotless/pull/94), [#89](https://github.com/diffplug/spotless/pull/89), [#88](https://github.com/diffplug/spotless/pull/88), [#85](https://github.com/diffplug/spotless/pull/85))
* When special-purpose formatters need to be downloaded from maven, they are now resolved using the buildscript repositories rather than the project repositories. (thanks to [cal101](https://github.com/cal101) [#100](https://github.com/diffplug/spotless/pull/100))

### Version 3.2.0 - April 3rd 2017 ([javadoc](https://diffplug.github.io/spotless/javadoc/spotless-plugin-gradle/3.2.0/), [jcenter](https://bintray.com/diffplug/opensource/spotless-plugin-gradle/3.2.0))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
*/
package com.diffplug.gradle.spotless;

import java.util.logging.Level;
import java.util.logging.Logger;

import org.gradle.api.Project;
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.artifacts.Dependency;
Expand All @@ -27,12 +30,19 @@ private GradleProvisioner() {}

public static Provisioner fromProject(Project project) {
return mavenCoords -> {
Dependency[] deps = mavenCoords.stream()
.map(project.getDependencies()::create)
.toArray(Dependency[]::new);
Configuration config = project.getConfigurations().detachedConfiguration(deps);
config.setDescription(mavenCoords.toString());
return config.resolve();
try {
Dependency[] deps = mavenCoords.stream()
.map(project.getBuildscript().getDependencies()::create)
.toArray(Dependency[]::new);
Configuration config = project.getBuildscript().getConfigurations().detachedConfiguration(deps);
config.setDescription(mavenCoords.toString());
return config.resolve();
} catch (Exception e) {
logger.log(Level.SEVERE, "You probably need to add a repository containing the '" + mavenCoords + "' artifact, e.g.: 'buildscript { repositories { mavenCentral() }}'", e);
throw e;
}
};
}

private static final Logger logger = Logger.getLogger(GradleProvisioner.class.getName());
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ public class FreshMarkExtensionTest extends GradleIntegrationTest {
@Test
public void integration() throws IOException {
write("build.gradle",
"buildscript { repositories { mavenCentral() } }",
"plugins {",
" id 'java'",
" id 'com.diffplug.gradle.spotless'",
"}",
"repositories { mavenCentral() }",
"spotless {",
" freshmark {",
" properties {",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ public class GoogleJavaFormatIntegrationTest extends GradleIntegrationTest {
@Test
public void integration() throws IOException {
write("build.gradle",
"buildscript { repositories { mavenCentral() } }",
"plugins {",
" id 'com.diffplug.gradle.spotless'",
"}",
"repositories { mavenCentral() }",
"",
"spotless {",
" java {",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ public class JavaDefaultTargetTest extends GradleIntegrationTest {
@Test
public void integration() throws IOException {
write("build.gradle",
"buildscript { repositories { mavenCentral() } }",
"plugins {",
" id 'com.diffplug.gradle.spotless'",
"}",
"repositories { mavenCentral() }",
"",
"apply plugin: 'groovy'",
"",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ public class ScalaExtensionTest extends GradleIntegrationTest {
@Test
public void integration() throws IOException {
write("build.gradle",
"buildscript { repositories { mavenCentral() } }",
"plugins {",
" id 'com.diffplug.gradle.spotless'",
"}",
"apply plugin: 'scala'",
"repositories { mavenCentral() }",
"spotless {",
" scala {",
" scalafmt().configFile('scalafmt.conf')",
Expand Down
2 changes: 2 additions & 0 deletions spotlessSelf.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
buildscript { repositories { jcenter() }}

// applied by SelfTest
plugins {
id 'com.diffplug.gradle.spotless'
Expand Down

0 comments on commit dd90ab7

Please sign in to comment.