I have followed this guide for creating a custom task with Gradle. http://www.ysofters.com/2015/02/26/how-to-create-gradle-project-with-custom-task-classes-in-groovy/ I also had a look at the gradle doc. https://docs.gradle.org/current/userguide/custom_tasks.html
It's very clear, and I can get the examples to compile and use the tasks, so everythings fine so far.
However, examples only show the import of gradle api-files, i.e.
import org.gradle.api.DefaultTask
import org.gradle.api.tasks.TaskAction
I want to add some more dependencies i.e
import org.springframework.beans.factory.config.YamlPropertiesFactoryBean
import org.springframework.core.io.FileSystemResource
but I can do that - gradle will complain and say "unable to resolve class .."
I tried to also set up spring-core and apache-commons under the buildscript->dependencies closure in build.gradle but it didn't make any difference i.e.
buildscript {
dependencies {
classpath group: 'org.springframework', name: 'spring-core', version: springVersion
classpath group: 'org.apache.commons', name: 'commons-lang3', version: '3.4'
.....
So, what am I missing - how can I use third party dependencies in my custom task class?
you need to put a build.gradle file into your buildSrc
directory. You can checkout the buildSrc/build.gradle
file from the gradle project itself as an example: https://github.com/gradle/gradle/blob/v4.1.0/buildSrc/build.gradle
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With