Skip to content

Commit a0d9dbe

Browse files
committed
Use the new forbidRegex to protect against internal API.
1 parent 0ebfb12 commit a0d9dbe

File tree

1 file changed

+2
-14
lines changed

1 file changed

+2
-14
lines changed

gradle/spotless.gradle

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,5 @@
11
apply plugin: 'com.diffplug.spotless'
22
spotless {
3-
def noInternalDepsClosure = {
4-
String text = it
5-
/*
6-
* No good way to get around using this import:
7-
* https://github.com/gradle/gradle/issues/3191
8-
*/
9-
String regex = "import org\\.gradle\\.api\\.internal\\.(?!plugins\\.DslObject)(?!project\\.ProjectInternal)"
10-
if ((text.contains('import org.gradle.internal.') || text.find(regex)) &&
11-
!text.contains('def noInternalDepsClosure')) {
12-
throw new AssertionError("Accidental internal import")
13-
}
14-
}
153
if (project != rootProject) {
164
// the rootProject doesn't have any java
175
java {
@@ -22,9 +10,9 @@ spotless {
2210
eclipse().configFile rootProject.file('gradle/spotless.eclipseformat.xml')
2311
trimTrailingWhitespace()
2412
removeUnusedImports()
25-
removeWildcardImports()
2613
formatAnnotations()
27-
custom 'noInternalDeps', noInternalDepsClosure
14+
forbidWildcardImports()
15+
forbidRegex('ForbidGradleInternal', 'import org\\.gradle\\.api\\.internal\\.(.*)', "Don't use Gradle's internal API")
2816
}
2917
}
3018
groovyGradle {

0 commit comments

Comments
 (0)