Q:

How to check from within a Gradle file if a task has been or has not been excluded?

In a Gradle file is the following configuration:

publishing {
  publications {
    if (os == 'osx') {
      nebulaIvy(IvyPublication) {
        artifact('build/final/java_plugin-linux-x86_64/linux-x86_64.exe') {
          classifier 'linux-x86_64'
          extension 'exe'
          type 'exe'
        }
      }
    }

The Linux binary is built through the task buildInDocker. If the buildInDocker task is excluded (eg gradlew -x buildInDocker), that part of the configuration shouldn't be done. How can this be done?

A:

Use https://docs.gradle.org/current/javadoc/org/gradle/StartParameter.html#getExcludedTaskNames(): !project.getGradle().startParameter.getExcludedTaskNames().contains('buildInDocker').

