You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a custom rule to enforce all dependency versions are coming from a java-platform or Spring constraint, and I want it to hard-error instead of trimming off the version string.
custom 'Drop version portion of dependency', {
def match
if ((match = it =~ /(\s*\S*(?:api|[cC]ompileOnly|[rR]untimeOnly|[iI]mplementation|[tT]est))\('([\w.-]+):([\w.-]+):([\w.-]+)'\)/)) {
throw new AssertionError("Error in: ${target} ${match.group(0)}.\nDo not declare raw dependency versions in project Gradle files. 'spotlessApply' cannot resolve this issue.\n")
}
How can I allow a developer to temporarily play with a custom version override using spotless:off/spotless:on with a rule like this that does an AssertionError?
The text was updated successfully, but these errors were encountered:
I think that will be very tricky to do using spotless:off, see #691 for how it works under the hood.
Much easier I think would be for your rule to look for // #allowRawDeps, in which case it disables itself. Your error message can say "Disable this temporarily with // #allowRawDeps".
custom 'Do not use raw dependency versions. Prefer constraints.', { String fileAsStr ->
fileAsStr.eachLine {thisLine , count ->
def match
if ((match = thisLine =~ /(\s*\S*(?:api|[cC]ompileOnly|[rR]untimeOnly|[iI]mplementation|[tT]est))\('([\w.-]+):([\w.-]+):([\w.-]+)'\).*$/)) {
if (!match.group(0).contains("spotless:ignore")) {
throw new AssertionError("Error in ${target} line ${count+1}:\n${match.group(0)}\nDo not declare raw dependency versions in project Gradle files. 'spotlessApply' cannot resolve this issue.\n")
}
}
}
fileAsStr
}
Testing against a strings like
distributedTestRuntimeOnly('org.springframework:spring-oxm:5.3.9') // spotless:ignore <-- OK
distributedTestRuntimeOnly('junit:junit:4.3.2') <-- errors
I have a custom rule to enforce all dependency versions are coming from a
java-platform
or Spring constraint, and I want it to hard-error instead of trimming off the version string.How can I allow a developer to temporarily play with a custom version override using
spotless:off
/spotless:on
with a rule like this that does anAssertionError
?The text was updated successfully, but these errors were encountered: