# Maven-publish and setting snapshotRepository and releaseRepository

**URL:** <https://discuss.gradle.org/t/maven-publish-and-setting-snapshotrepository-and-releaserepository/5549>\
**Category:** Old Forum Archive\
**Created:** [May 7, 2013, 10:38am UTC](https://discuss.gradle.org/t/maven-publish-and-setting-snapshotrepository-and-releaserepository/5549 "2013-05-07T10:38:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![u1234](https://avatars.discourse-cdn.com/v4/letter/u/2acd7d/32.png) [@u1234](https://discuss.gradle.org/u/u1234)\
**Post date:** [May 7, 2013, 10:38am UTC](https://discuss.gradle.org/t/maven-publish-and-setting-snapshotrepository-and-releaserepository/5549/1 "2013-05-07T10:38:00Z")

</div>

I am updating our build scripts to use the “maven-publish” plugin instead of the “maven” plugin. Previously we did:

```gradle
apply plugin: 'maven'
  repositories {
  maven {
    url "http://internal.repo"
  }
}
  uploadArchives {
  repositories {
    mavenDeployer {
      snapshotRepository(url: "http://internal.repo/libs-snapshot-local") {
        authentication(userName: 'admin', password: 'password')
      }
      repository(url: "http://internal.repo/libs-release-local") {
        authentication(userName: 'admin', password: 'password')
      }
    }
  }
}

```

The updated version looks like this:

```gradle
apply plugin: 'maven-publish'
  repositories {
  maven {
    url "http://internal.repo"
  }
}
  publishing {
  publications {
    mavenJava(MavenPublication) {
      from components.java
    }
  }
  repositories {
    maven {
      credentials {
        username "admin"
        password "password"
      }
      url
"http://internal.repo/libs-snapshot-local"
    }
  }
}

```

But there is no “snapshotRepository” element. So how do I setup snapshot/release repositories when using the maven-publish plugin?

---

<div class="post-metadata">

**Author:** ![Peter\_Niederwieser](https://avatars.discourse-cdn.com/v4/letter/p/9f8e36/32.png) [@Peter\_Niederwieser](https://discuss.gradle.org/u/Peter_Niederwieser)\
**Post date:** [May 7, 2013, 11:02am UTC](https://discuss.gradle.org/t/maven-publish-and-setting-snapshotrepository-and-releaserepository/5549/2 "2013-05-07T11:02:00Z")

</div>

You can set a different repository URL based on the project version (if-statement).

---

<div class="post-metadata">

**Author:** ![u1234](https://avatars.discourse-cdn.com/v4/letter/u/2acd7d/32.png) [@u1234](https://discuss.gradle.org/u/u1234)\
**Post date:** [May 7, 2013, 2:45pm UTC](https://discuss.gradle.org/t/maven-publish-and-setting-snapshotrepository-and-releaserepository/5549/3 "2013-05-07T14:45:00Z")

</div>

Do it directly in a script works but when I try to move it to my common plugin:

```gradle
void setup(Project project) {
      project.publishing {
      publications {
        mavenJava(MavenPublication) { from components.java }
      }
      repositories {
        maven {
          credentials {
            username "admin"
            password "password"
          }
            if(project.version.endsWith('-SNAPSHOT')) {
            url "http://my/artifactory/libs-snapshot-local"
          } else {
            url "http://my/artifactory/libs-release-local"
          }
        }
      }
    }

```

I get:

```gradle
* What went wrong:
A problem occurred configuring the 'publishing' extension
> Could not find property 'components' on org.gradle.api.publish.maven.internal.publication.DefaultMavenPublication_Decorated@145a25f3.

```

where component.java is:

SoftwareComponentContainer org.gradle.api.Project.getComponents()

Do I miss a dependency to find the component when calling it on a plugin?

---

<div class="post-metadata">

**Author:** ![Peter\_Niederwieser](https://avatars.discourse-cdn.com/v4/letter/p/9f8e36/32.png) [@Peter\_Niederwieser](https://discuss.gradle.org/u/Peter_Niederwieser)\
**Post date:** [May 7, 2013, 2:49pm UTC](https://discuss.gradle.org/t/maven-publish-and-setting-snapshotrepository-and-releaserepository/5549/4 "2013-05-07T14:49:00Z")

</div>

It’s ‘project.components.java’. Or you wrap the whole method body with ‘project.configure(project) { … }’ to get the same ‘project’ scope as in a build script.
