I have a project with 2 subprojects, and I need to...
# community-support
r
I have a project with 2 subprojects, and I need to take the jar file produced by each project and copy it for packaging as an app. In my experiments to move things into a configuration cache-compatible state, and I wonder if there's a better way or anything that could be improved. I ended up adding a configuration that is published by each subproject (
shippingJar
), and then in my root build script creating configurations for each jar (they need to be in different places) by depending on them like so:
Copy code
dependencies {
  shippingIJ project(path: ':ij', configuration: 'shippingJar')
}
And then I use those in a shared copyspec:
Copy code
def commonDist = project.copySpec {
    if (configurations.shippingIJ.files.size() != 1) {
        throw new GradleException("shippingIJ configuration must contain exactly one file")
    }

    from(configurations.shippingIJ) {
        into ''
    }
}
This seems to work with the cache, and everything using the copyspec seems to correctly handle the task dependencies on the subprojects. This is much nicer than the manual file paths and task deps. I was doing before.
v
Actually, it is not ugly enough 😄 Configurations should be either for consumption, or for resolving, or for declaration. Your
shippingIJ
is for resolving and declaration. 🙂 Regarding that size check, you can probably just do
.files.singleFile
or what it was called. And besides that, I strongly recommend switching to Kotlin DSL. By now it is the default DSL, you immediately get type-safe build scripts, actually helpful error messages if you mess up the syntax, and amazingly better IDE support if you use a good IDE like IntelliJ IDEA or Android Studio. 🙂
r
It is a lot nicer, so glad it's not crazy! singleFile looks like what I wanted, thanks! I was thinking about switching to Kotlin, but still not sure. I see in the project board kotlin will become recommended for all projects. Is it not now despite being the default? What are the plans regarding groovy, deprecation or removal?
v
deprecation or removal
Not as far as I know. But anyone not using Kotlin DSL is just hurting themselves. 🙂
I see in the project board kotlin will become recommended for all projects.
Afair very very big projects could maybe suffer some performance problems in some situations or something like that. While actually in some situations Kotlin DSL is also faster than Groovy DSL. I use it since years in small to mid projects without significant problems.
r
Might be worth trying one day. Thanks for the help!
👌 1
that's odd, using
configurations.shippingIJ.singleFile
breaks the automatic task dependency chain, using clean build with singleFile results in it not building the subproject, but when just using
configurations.shippingIJ
it will build the subproject automatically
v
No, that's not strange, that's expected. With
singleFile
you make it a
File
.
File
does not have any dependency information.
In the
from
the configuration should stay, or you do some syntax trick like
configurations.shippingIJ.tap { it.singleFile }
or similar
r
hmm, I think I'll stick with the exceptions then. thanks
🤷‍♂️ 1