Make build dependsOn custom task

One of my subprojects A dependsOn another subproject B. I had been using this line to declare a dependency, and things worked just fine.

   evaluationDependsOn(':B')

I just moved to Gradle 3.3. And am now getting this error

 Declaring custom 'build' task when using the standard Gradle lifecycle plugins is not allowed.

The general problem is: how do I make my custom tasks hook into the predefined tasks – specifically task build and task publish. There are lots of suggestions on various forums, but none of them work for me. The most promising seemed to be (inside subproject A)

project.afterEvaluate {
build.dependsOn project(’:B’).task(‘build’)
}

I’ve also considered that perhaps I’m trying to improperly architect my build file. Option (1) task “build” should generically build all build-like things. Option (2) “build” is only for Java build, and I should create my own top-level task (say “myBuild” that depends on Java’s “build”.

The error message implies that you are creating a task named ‘build’, which is no longer allowed if the ‘build’ task is already being supplied by the standard Gradle plugins.

Does the output point you at the offending code? For example, this:

apply plugin: 'base'
task build

tells me that the offending code is on line 2:

$ ./gradlew tasks

FAILURE: Build failed with an exception.

* Where:
Build file '/home/cdore/gradle-tests/gradle-dupbuild-test/build.gradle' line: 2

* What went wrong:
A problem occurred evaluating root project 'gradle-confforce-test'.
> Declaring custom 'build' task when using the standard Gradle lifecycle plugins is not allowed.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

What is the offending code in your case?

The offending line is

 build.dependsOn project(':DockerBase').task('build') 

Does adding a dependsOn link to build really change the build task? Is there another way I can add a dependency to a built-in task? If so, how?

I see, sorry I missed it in your original post. task(String) creates a task, it does not get a reference to an existing task.

Use the tasks container instead. For example:

build.dependsOn project(':DockerBase').tasks.build

I missed that distinction. Your solution fixed my problem(s).

Thanks Chris !