Circular dependency between tasks. Cycle includes [task ':javadoc', task ':javadoc']

I am working on developing a plugin that

  1. Adds a sourceset,

  2. Compiles this sourceset,

  3. Adds the compiled classes to a jar 4. Specifies the jar file as the artifact of a custom configuration

In a project I am using to try this plugin out my main configuration depends on the artifact in my custom configuration, like this :

compile project(path: ':',
configuration: 'service')

But now when I run gradle javadoc, I get the following error :

Circular dependency between tasks. Cycle includes [task ‘:javadoc’, task ‘:javadoc’]

Does anyone have any idea why this happens ?

The plugin source can be viewed at : https://github.com/jelmerk/liferay-gradle-plugin/blob/master/src/main/java/nl/orange11/liferay/ServiceBuilderPlugin.java

My full test script looks like this :

buildscript {
    repositories {
  mavenLocal()
  mavenCentral()
    }
    dependencies {
        classpath group: 'nl.orange11.liferay', name: 'liferay-plugin', version: '0.0.1-SNAPSHOT'
    }
}
  buildscript {
   configurations.classpath.resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
}
  apply plugin: 'liferay-portlet'
apply plugin: 'liferay-servicebuilder'
  repositories {
    mavenLocal()
    mavenCentral()
}
  dependencies {
    providedCompile 'javax.servlet:servlet-api:2.5'
    providedCompile 'javax.servlet.jsp:jsp-api:2.1'
    providedCompile 'com.liferay.portal:portal-service:6.1.0'
    providedCompile 'com.liferay.portal:util-java:6.1.0'
    providedCompile 'com.liferay.portal:util-bridges:6.1.0'
    providedCompile 'com.liferay.portal:util-taglib:6.1.0'
              compile project(path: ':',
configuration: 'service')
          serviceCompile 'com.liferay.portal:portal-service:6.1.0'
}
  liferay {
 appServerDirName = '/Users/jkuperus/Development/Projects/liferay_6_1_ga1/build/portal/apache-tomcat/'
}
  servicebuilder {
 jalopyInputFileName = file('jalopy.xml')
}

I actually did a bit of debugging and the problem is in the way the JavaPlugin sets up the javadoc task

Basicallly it does this :

Javadoc javadoc = project.getTasks().add(JAVADOC_TASK_NAME, Javadoc.class);
....
addDependsOnTaskInOtherProjects(javadoc, true, JAVADOC_TASK_NAME, COMPILE_CONFIGURATION_NAME);

Where addDependsOnTaskInOtherProjects looks like this

private void addDependsOnTaskInOtherProjects(final Task task, boolean useDependedOn, String otherProjectTaskName,
                                                 String configurationName) {
        Project project = task.getProject();
        final Configuration configuration = project.getConfigurations().getByName(configurationName);
        task.dependsOn(configuration.getTaskDependencyFromProjectDependency(useDependedOn, otherProjectTaskName));
    }

This means that you always get a circular dependency if you depend on an artifact in another configuration of the same project

Does anyone have a solution for this ? It feels kind of like a bug to me, or at least something thats not configurable enough

It’s uncommon to depend on a configuration from the same project in this way. Can you get around this? Otherwise, a potential hack is to overwrite the ‘javadoc’ task’s task dependencies. (Probably the Java plugin should be smart enough not to make the Javadoc task depend on itself.) Not sure if this will be the only problem though.