Alternative to `libsDir`

We recently updated to a newer version of Gradle, which caused following warnings:

The libsDir method has been deprecated.

Anybody know what the alternative is? I have found nothing in the documentation, nothing in de source code, nothing in the commit that deprecated it.

I have searched the forums for similar messages, but the only semi-relevant post has no answer either.

1 Like

Please include the relevant snippets from your build.gradle so we can understand what you’re trying to achieve

So I basically have a Spring Boot server, which will submit jobs to a Spark cluster. To run these jobs on Spark, I must somehow get the jar with the job code (in Java) to the cluster. To avoid doing things manually, I thought it would be nice if my Spring application could upload the jar on server start.

Therefor I’m trying to add the job jar as a resource to my Spring App. The project structure is as follows:

main
├── spark (small pure Java module with Spark job code)
├── ... other modules
└── rest (Spring Boot server)

Relevant snippet from Gradle (copies fat jar from subproject to main project resources):

gradle.projectsEvaluated {

	task addSparkJobs(type: Copy, dependsOn: ":spark:shadowJar") {
		description "Ensures job jar for Spark is present"
		from project(':spark').libsDir
		include 'spark-*-all.jar'
		rename '.*', 'spark-all.jar'
		into "${sourceSets.main.output.resourcesDir.toString()}/jobs/"
	}

	jar.dependsOn addSparkJobs
}

I get the feeling you could replace

from project(':spark').libsDir
include 'spark-*-all.jar'

With

from project(':spark').tasks['shadowJar'] 

Most of Gradle’s file based task methods (eg Copy.from(…)) accept Object for a file which can be many different things, including a Task instance

See Project.files(Object…)

A Task . Converted to the task’s output files. The task is executed if the file collection is used as an input to another task.

I’m guessing you could also replace

gradle.projectsEvaluated {...} 

With

evaluationDependsOn ':spark' 

See Project.evaluationDependsOn(…)

2 Likes

Thanks a lot, this works exactly as I want it to!

How to do the same thing from a snippet that does a few subprojects to gather all the jars for a project into a staging directory like so

subprojects {


task syncJars(type: Sync, dependsOn: ‘jar’) {
from(configurations.compile) {}
from(fixedLibDir) {}
from(libsDir) {}
into toStagingDir
}

}

I am not sure how to convert libsDir in this case

You need to think about which task created the jar rather than the location of the jars. Perhaps

task syncJars(type: Sync) {
   from tasks.withType(Jar)
   ... 
}