Hello, hello!
While modernizing one of my projects I found a curious issue. If you use both java-library
plugin (to get the api
configuration), and the groovy
plugin (to compile some groovy code for your library), things work fine for producing a jar
file and publishing to a repo.
What doesn’t work is if you try to consume this project within the same build. The best workaround I’ve found is to use compile
instead of api
.
Is it intentional? Am I missing something? What is the way forward?
Here is a repro:
settings.gradle
include 'subproject
build.gradle
plugins {
id 'groovy'
id 'java-library'
}
dependencies {
implementation localGroovy()
}
def j = file('src/main/java/Foo.java')
def g = file('src/main/groovy/Bar.groovy')
def d = file('subproject/src/main/java/Using.java')
[j, g, d].each { assert it.parentFile.directory || it.parentFile.mkdirs() }
j.text = 'class Foo {}'
g.text = 'class Bar {}'
d.text = 'class Using { Foo foo; Bar bar; }'
assemble{
dependsOn('clean')
doLast {
assert fileTree('build/classes').asCollection().size()==2
}
}
project(':subproject') {
apply plugin: 'java'
dependencies.implementation(rootProject)
compileJava {
doFirst {
println classpath.asCollection().join('\n')
}
}
}