Java-library - enforce jar file to be build if added to another projects custom configuration

Hello,

I try depend on a java-library “anotherProject” within a multi project build like :

project.dependencies.add("myconfiguration", project.findProject("anotherProject"))

I need to extract the files of myconfiguration:

project.configurations.getByName("myconfiguration").asFileTree.forEach {...}

BUT: This may causes a file not found exception of the .jar of “anotherProject” because the jar task of anotherProject is never executed - but the configuration contains already the jar file name. Is there a standard way to ensure the .jar artifact is build without introducing direct project task dependency?

Hi @bs-git,

Yes. You have to define your configuration as input to the task doing the file extraction. You can use @InputFiles or @Classpath to mark input properties if you define the task in a class (recommended). You also can add inputs dynamically like this:

tasks.create("...") {
    inputs.files(project.configurations.getByName("myconfiguration"))
}
1 Like

Your solution works great (I use the inputs.files(…) variant now). Thank you!

1 Like