# Jar task does not see dependency when using maven-publish

**URL:** <https://discuss.gradle.org/t/jar-task-does-not-see-dependency-when-using-maven-publish/11091>\
**Category:** Bugs\
**Created:** [August 10, 2015, 12:38pm UTC](https://discuss.gradle.org/t/jar-task-does-not-see-dependency-when-using-maven-publish/11091 "2015-08-10T12:38:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Radim\_Kubacki](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/radim_kubacki/32/1032_2.png) [@Radim\_Kubacki](https://discuss.gradle.org/u/Radim_Kubacki)\
**Post date:** [August 10, 2015, 12:38pm UTC](https://discuss.gradle.org/t/jar-task-does-not-see-dependency-when-using-maven-publish/11091/1 "2015-08-10T12:38:07Z")

</div>

We have a build using maven-publish and want to include pom.xml into published JAR (discussed for example in [https://issues.gradle.org/browse/GRADLE-2916](https://issues.gradle.org/browse/GRADLE-2916)). The build works: it creates JARs and publishes them. But when we run `gradle tasks` it fails. Simple version of a build to reproduce looks like this:

settings.gradle:

```
include 'a'
include 'b'

```

build.gradle:

```
subprojects {
    apply plugin: 'java'
    apply plugin: 'maven-publish'

    jar {
        dependsOn 'generatePomFileForMavenJavaPublication'
        into("META-INF/maven/$project.group/$project.archivesBaseName") {
            from new File(project.buildDir, 'publications/mavenJava')
            rename ".*", "pom.xml"

        }
    }

    publishing {
        publications {
             mavenJava(MavenPublication) {
                from components.java
            }
        }
        repositories {
            maven {
                name 'local'
                url new File(rootProject.buildDir, 'repo').toURI().toURL()
            }
        }
    }
}

```

b/build.gradle:

```
dependencies {
    compile project(':a')
}

```

The error looks like:

```
Execution failed for task ':tasks'.
> Could not determine the dependencies of task ':aggrDaoProtos:jar'.
...
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':tasks'.
Caused by: org.gradle.api.GradleException: Could not determine the dependencies of task ':aggrDaoProtos:jar'.
Caused by: org.gradle.api.UnknownTaskException: Task with path 'generatePomFileForMavenJavaPublication' not found in project ':aggrDaoProtos'.

```

Same with Gradle 2.5 and 2.6-rc-2. Any idea what is wrong?

---

<div class="post-metadata">

**Author:** ![daz](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/daz/32/2475_2.png) [@daz](https://discuss.gradle.org/u/daz)\
**Post date:** [August 14, 2015, 9:20pm UTC](https://discuss.gradle.org/t/jar-task-does-not-see-dependency-when-using-maven-publish/11091/2 "2015-08-14T21:20:46Z")

</div>

Thanks Radim.

The publishing tasks are all created via the new configuration model, which means they suffer from issues around bridging between the new and old models. Another case is the use of `Tasks.withType()`.

This looks like another use case where task bridging doesn’t seem to be working fully. I’ve verified that the supplied test fails, but I don’t yet understand why.

I found 2 ways to make ‘gradle tasks’ work :

1. add `tasks.realize()` to the end of the build script for ‘:b’
2. Remove the project dependency from the build script for ‘:b’

@Adrian_Kelly Please take a look at this as part of your design work for task bridging.

---

<div class="post-metadata">

**Author:** ![Radim\_Kubacki](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/radim_kubacki/32/1032_2.png) [@Radim\_Kubacki](https://discuss.gradle.org/u/Radim_Kubacki)\
**Post date:** [August 14, 2015, 11:15pm UTC](https://discuss.gradle.org/t/jar-task-does-not-see-dependency-when-using-maven-publish/11091/3 "2015-08-14T23:15:57Z")

</div>

Hi Daz, thanks for looking into this. I suspected that the new configuration model will be involved. 1) looks interesting. Certainly it seems more elegant than

```
if (project.tasks.findByName('generatePomFileForMavenJavaPublication')) {
    dependsOn 'generatePomFileForMavenJavaPublication'
} else {
    project.tasks.whenTaskAdded { addedTask ->
        if (addedTask.name == 'generatePomFileForMavenJavaPublication') {
            project.tasks.jar.dependsOn 'generatePomFileForMavenJavaPublication'
        }
    }
}

```

Using 2) is not an option when the example is simplified version of our setup with these dependencies.

---

<div class="post-metadata">

**Author:** ![Adrian\_Kelly](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/adrian_kelly/32/106_2.png) [@Adrian\_Kelly](https://discuss.gradle.org/u/Adrian_Kelly)\
**Post date:** [August 15, 2015, 10:56am UTC](https://discuss.gradle.org/t/jar-task-does-not-see-dependency-when-using-maven-publish/11091/4 "2015-08-15T10:56:46Z")

</div>

Yep, it’s related to task bridging. The design spec is [here](http://github.com/gradle/gradle/blob/master/design-docs/task-bridging.md) and we hope to start work on this soon.
