Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Task not found in root project

I am confused by gradle build lifecycle for a few days. Refer tells me

A Gradle build has three distinct phases.

  • Initialization
  • Configuration
  • Execution

Is task creation in the third step? If so, how does gradle find all tasks in a project object?

Here is an example.

 rootporject
       |----app
            |----build.gradle
            |----checkstyle.gradle

The build.gradle is as simple as normal.checkstyle.gradle file has a task. Here is its content.

apply plugin: 'checkstyle'

task checkstyle(type:Checkstyle) {
    description 'Runs Checkstyle inspection against girl sourcesets.'
    group = 'Code Quality'
    configFile rootProject.file('checkstyle.xml')
    ignoreFailures = false
    showViolations true
    classpath = files()
    source 'src/main/java'
}

After ./gradlew -q tasks, there is no task checkstyle.

But if I remove the definition into build.gradle, I get it.

Is there anything wrong?Thanks in advance.

Edit

From doc

There is a one-to-one relationship between a Project and a build.gradle file.

like image 442
CoXier Avatar asked Sep 14 '17 13:09

CoXier


1 Answers

You haven't applied your other script.

In your build.gradle you should add an apply from: 'checkstyle.gradle'.

like image 114
mkobit Avatar answered Oct 29 '22 01:10

mkobit