Skip to content

Commit 4fe893c

Browse files
committed
Update error message if plugin is applied in the wrong file
That also changes the IllegalStateException to an IllegalArgumentException
1 parent d5335a5 commit 4fe893c

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

plugins/dependencies/src/main/kotlin/de/fayard/refreshVersions/RefreshVersionsPlugin.kt

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import org.gradle.api.DefaultTask
1010
import org.gradle.api.Plugin
1111
import org.gradle.api.Project
1212
import org.gradle.api.initialization.Settings
13+
import org.gradle.api.invocation.Gradle
1314
import org.gradle.kotlin.dsl.*
1415

1516
open class RefreshVersionsPlugin : Plugin<Any> {
@@ -32,15 +33,21 @@ open class RefreshVersionsPlugin : Plugin<Any> {
3233

3334

3435
override fun apply(target: Any) {
35-
when (target) {
36-
is Settings -> bootstrap(target)
37-
is Project -> error(
38-
"""
39-
Gradle plugins.id("de.fayard.refreshVersions") must be configured in settings.gradle(.kts), not in build.gradle(.kts)
40-
See https://jmfayard.github.io/refreshVersions/setup/
41-
""".trimIndent()
42-
)
36+
require(target is Settings) {
37+
val notInExtraClause: String = when (target) {
38+
is Project -> when (target) {
39+
target.rootProject -> ", not in build.gradle(.kts)"
40+
else -> ", not in a build.gradle(.kts) file."
41+
}
42+
is Gradle -> ", not in an initialization script."
43+
else -> ""
44+
}
45+
"""
46+
plugins.id("de.fayard.refreshVersions") must be configured in settings.gradle(.kts)$notInExtraClause.
47+
See https://jmfayard.github.io/refreshVersions/setup/
48+
""".trimIndent()
4349
}
50+
bootstrap(target)
4451
}
4552

4653
private fun bootstrap(settings: Settings) {

0 commit comments

Comments
 (0)