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
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.
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