오래된 멀티 프로젝트 빌드를 Groovy DSL에서 Kotlin DSL로 옮기는 중입니다. 루트 build.gradle에는 이런 블록이 있었습니다.
subprojects {
apply plugin: 'java-library'
repositories { mavenCentral() }
}
루트는 기계적으로 옮겼습니다.
subprojects {
apply(plugin = "java-library")
repositories { mavenCentral() }
}
순서대로 정리하겠습니다.
루트 스크립트는 컴파일됩니다. 여기는 문제가 없습니다.
서브프로젝트 core/build.gradle.kts에서는 dependencies 안의 implementation(project(":util")) 줄이 implementation을 찾지 못한다는 unresolved reference로 스크립트 컴파일을 멈춥니다. Groovy에서는 같은 줄이 잘 돌았습니다.
설명이 안 되는 건 세 번째입니다. 같은 파일 맨 위에 plugins { id("java-library") }를 넣으면 에러가 사라집니다. 루트가 이미 그 플러그인을 적용하고 있는데도 말입니다. 플러그인도 같고 프로젝트도 같은데 왜 접근자만 없어지는 겁니까? 그리고 서브프로젝트마다 plugins 블록을 반복하는 게 정말 의도된 해법입니까?
영어에서 번역·원문 보기Moving an old multi-project build from the Groovy DSL to the Kotlin DSL. The root build.gradle had this block.
subprojects {
apply plugin: 'java-library'
repositories { mavenCentral() }
}
The root I converted mechanically.
subprojects {
apply(plugin = "java-library")
repositories { mavenCentral() }
}
In order, then.
The root script compiles. No problem there.
In the subproject core/build.gradle.kts, the line implementation(project(":util")) inside dependencies stops script compilation with an unresolved reference to implementation. The same line worked under Groovy.
Case three is the one I can't explain. Put plugins { id("java-library") } at the top of that same file and the error goes away, even though the root was already applying the plugin. Same plugin, same project, so why do only the accessors disappear? And is repeating a plugins block in every subproject really the intended fix?