I include a second gradle file my.gradle in my build.gradle file.
The content of my.gradle is:
apply plugin: MyPlugin
class MyPlugin implements Plugin<Project> {
    @Override
    void apply(Project project) {
       project.tasks.create(name: "myTask", type: MyTaskClass) {
       }
    }
}
In my build.gradle I set at the top: 
apply from: 'myPlugin.gradle'
Now I want to set a task dependency in build.gradle with: 
tasks.myPlugin.myTask.dependsOn += someOtherTask
When I build I get the following error:
> Could not find property 'myPlugin' on task set.
How can I access myTask from myPlugin in build.gradle?
Edit: I tried to make sure that someTask runs after myTask. I tried to do this with:
taskX.finalizedBy taskY
in my case:
tasks.myPlugin.myTask.finalizedBy someOtherTask
but the former does not work.
To add a dependency to your project, specify a dependency configuration such as implementation in the dependencies block of your module's build.gradle file.
If the task you want to pass parameters to is of type JavaExec and you are using Gradle 5, for example the application plugin's run task, then you can pass your parameters through the --args=... command line option. For example gradle run --args="foo --bar=true" .
Tasks can also be created and extended dynamically at runtime. The following listing represents a very simple build file. To execute the hello task in this build file, type gradle hello on the command line in the directory of the build file.
The following script will do the job:
my.gradle:
apply plugin: MyPlugin
class MyPlugin implements Plugin<Project> {
    @Override
    void apply(Project project) {
       project.tasks.create(name: "myTask", type: Copy) {
       }
    }
}
build.gradle:
apply from: 'my.gradle'
task someOtherTask << {
   println 'doLast'
}
project.tasks.myTask.dependsOn(someOtherTask)
                        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