# Dependency between publications and distTar

**URL:** <https://discuss.gradle.org/t/dependency-between-publications-and-disttar/6396>\
**Category:** Old Forum Archive\
**Created:** [February 4, 2015, 4:20pm UTC](https://discuss.gradle.org/t/dependency-between-publications-and-disttar/6396 "2015-02-04T16:20:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Martin\_d\_Anjou](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/martin_d_anjou/32/5248_2.png) [@Martin\_d\_Anjou](https://discuss.gradle.org/u/Martin_d_Anjou)\
**Post date:** [February 4, 2015, 4:20pm UTC](https://discuss.gradle.org/t/dependency-between-publications-and-disttar/6396/1 "2015-02-04T16:20:00Z")

</div>

How do I make publications depend on distTar? The error I keep getting is:

```gradle
Invalid publication 'mavenJava': artifact file does not exist: '/path/to/my/project-0.1.0-SNAPSHOT.tgz'

```

Here is an excerpt of my build.gradle (2.2.1) file:

```gradle
distTar {
  compression = Compression.GZIP
}
distributions {
  main {
    baseName = project.name
    contents {
      into('bin') {
        from 'bin'
      }
      into('lib') {
        from 'lib'
      }
  }
}
publishing {
  publications {
    mavenJava(MavenPublication) {
      artifact(distTar.archivePath)
    }
  }
  repositories {
    maven {
      url "$buildDir/repository"
    }
  }
}

```

However, when I type gradle distTar, it does create the dist file aforementioned, and after that I can run gradle publish. How do I make the publish task depend on distTar? I tried adding publications (dependsOn:‘distributions’) but that did not work as I get:

```gradle
Could not find method publishing() for arguments [{dependsOn=distributions}, ...

```

Thanks.

---

<div class="post-metadata">

**Author:** ![Mark\_Viera](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/mark_viera/32/1543_2.png) [@Mark\_Viera](https://discuss.gradle.org/u/Mark_Viera)\
**Post date:** [February 4, 2015, 5:39pm UTC](https://discuss.gradle.org/t/dependency-between-publications-and-disttar/6396/2 "2015-02-04T17:39:00Z")

</div>

Assuming the task ‘distTar’ is of type ‘Tar’ then you can simply do ‘artifact distTar’ which creates an implicit dependency. In fact, you can pass any instance of [‘AbstractArchiveTask’](http://gradle.org/docs/current/javadoc/org/gradle/api/tasks/bundling/AbstractArchiveTask.html) to the ‘artifact()’ method.

---

<div class="post-metadata">

**Author:** ![Mickey\_Killianey](https://avatars.discourse-cdn.com/v4/letter/m/7c8e57/32.png) [@Mickey\_Killianey](https://discuss.gradle.org/u/Mickey_Killianey)\
**Post date:** [February 25, 2015, 6:47pm UTC](https://discuss.gradle.org/t/dependency-between-publications-and-disttar/6396/3 "2015-02-25T18:47:00Z")

</div>

FWIW, if the task distTar _wasn’t_ of type Tar, or if you wanted to be more explicit, another option is to set the “builtBy” for your artifact:

```gradle
publishing {
  publications {
    mavenJava(MavenPublication) {
      artifact(distTar.archivePath) {
        builtBy: distTar
      }
    }
  }
}

```

I’m unclear whether this has _exactly_ the same effect as Mark’s suggestion, or if the result is subtly different.

---

<div class="post-metadata">

**Author:** ![Mark\_Viera](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/mark_viera/32/1543_2.png) [@Mark\_Viera](https://discuss.gradle.org/u/Mark_Viera)\
**Post date:** [February 26, 2015, 12:54am UTC](https://discuss.gradle.org/t/dependency-between-publications-and-disttar/6396/4 "2015-02-26T00:54:00Z")

</div>

The end result of Mickey’s solution is the same. In that case you are simply explicitly stating the build dependency, rather than having Gradle infer it from the task.

---

<div class="post-metadata">

**Author:** ![Martin\_d\_Anjou](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/martin_d_anjou/32/5248_2.png) [@Martin\_d\_Anjou](https://discuss.gradle.org/u/Martin_d_Anjou)\
**Post date:** [February 26, 2015, 3:35pm UTC](https://discuss.gradle.org/t/dependency-between-publications-and-disttar/6396/5 "2015-02-26T15:35:00Z")

</div>

In case someone (including me) comes looking for the final answer, this works:

```gradle
apply plugin: 'distribution'
apply plugin: 'maven-publish'
  distTar {
  compression = Compression.GZIP
}
distributions {
  main {
    baseName = project.name
    contents {
      from 'poems'
    }
  }
}
  publishing {
  publications {
    mavenJava(MavenPublication) {
      artifactId 'foo'
      groupId 'bar'
      version '1.0'
      artifact(distTar)
    }
  }
  repositories {
    maven {
      url "$buildDir/repository"
    }
  }
}

```

Execute with: gradle publish
