Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where can I put my custom task class in Gradle

Tags:

gradle

It's easy to write a custom plugin and include it in the build script

apply from: "utilities.gradle"

For test purpose this file is in the same directory as the build.gradle

Calling a task defined in utilities.gradle from build.gradle works without any hassle. In utilities gradle is also a plugin defined - configuring it from build.gradle just works.

But if I define a custom task in utilities.gradle calling it is no problem but if I want to use that custom taks in build.gradle it says

> Could not find property 'GreetingTask' on root project 'TestGradle'.

utilities.gradle:

task hello(type: GreetingTask)

class GreetingTask extends DefaultTask {
    @TaskAction
    def greet() {
        println 'hello from GreetingTask'
    }
 }

build.gradle

task hellox(type: GreetingTask)

Ok... I read the documentation here: http://www.gradle.org/docs/current/userguide/custom_tasks.html

It says the custom task is not visible outside... But then... how to share custom tasks with the team without making a Jar for everything. What I want is to place the utilities.gradle on a network drive and share it with the other.

pls help

like image 580
Mike Mitterer Avatar asked Jun 03 '13 06:06

Mike Mitterer


1 Answers

There is a special $rootDir/buildSrc directory which is its own build. All classes that this build produces are available to all build scripts in the "main" build. The buildSrc build has a default build.gradle, but you can add your own. By default, Java classes are expected under src/main/java, and Groovy classes under src/main/groovy. You can read more about buildSrc in the Gradle User Guide.

To share classes across multiple builds, a separate plugin project that publishes a Jar is the way to go.

like image 58
Peter Niederwieser Avatar answered Oct 05 '22 05:10

Peter Niederwieser