# Upload jar to local maven repository for each build type

**URL:** <https://discuss.gradle.org/t/upload-jar-to-local-maven-repository-for-each-build-type/1587>\
**Category:** Old Forum Archive\
**Created:** [January 20, 2015, 12:37pm UTC](https://discuss.gradle.org/t/upload-jar-to-local-maven-repository-for-each-build-type/1587 "2015-01-20T12:37:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![andy\_fin](https://avatars.discourse-cdn.com/v4/letter/a/58f4c7/32.png) [@andy\_fin](https://discuss.gradle.org/u/andy_fin)\
**Post date:** [January 20, 2015, 12:37pm UTC](https://discuss.gradle.org/t/upload-jar-to-local-maven-repository-for-each-build-type/1587/1 "2015-01-20T12:37:00Z")

</div>

I am developing an Android project with Android Studio & Gradle build.

I am using Gradle ‘maven-publish’ plugin to upload jar files to my local maven repo. I would like to upload jar for each build type. So I tried the following code:

```gradle
apply plugin: 'maven-publish'
  buildTypes {
    release {
     ...
    }
    debug {
     ...
    }
}
  android.applicationVariants.all { variant ->
      def buildType = variant.buildType.name
      publishing {
        repositories {
              url PATH-TO-MY-LOCAL-MAVEN-REPO
        }
          publications {
              create('myJar', MavenPublication ) {
                artifact
  "$projectDir/my.jar"
                artifactId
"myJar-$buildType" //artifactId indicates build type
                  groupId
  "com.my.app"
                version
  "2.1.1"
            }
          }
    }
      build.dependsOn(publish)
}

```

But Gradle complains with the following error:

```gradle
ERROR: Cannot configure the 'publishing' extension after it has been accessed.

```

How to get rid of this error? If it is a wrong way to do things, then how can I upload my jar for each build type to local maven then?

---

<div class="post-metadata">

**Author:** ![cmcginty](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/cmcginty/32/2209_2.png) [@cmcginty](https://discuss.gradle.org/u/cmcginty)\
**Post date:** [January 21, 2015, 12:59am UTC](https://discuss.gradle.org/t/upload-jar-to-local-maven-repository-for-each-build-type/1587/2 "2015-01-21T00:59:00Z")

</div>

try …

```gradle
publishing {
    publications {
        android.applicationVariants.all { variant ->
            create( ... ) { .... }
        }
    }
}

```

I have something similar to this in my build and it works fine. However I don’t use the android plugin, so there might be something going on inside of it that is resolving the publishing configuration.

---

<div class="post-metadata">

**Author:** ![andy\_fin](https://avatars.discourse-cdn.com/v4/letter/a/58f4c7/32.png) [@andy\_fin](https://discuss.gradle.org/u/andy_fin)\
**Post date:** [January 21, 2015, 10:05am UTC](https://discuss.gradle.org/t/upload-jar-to-local-maven-repository-for-each-build-type/1587/3 "2015-01-21T10:05:00Z")

</div>

Thanks, it works but not fullfill my purpose, could you please take a look at my question here : [http://forums.gradle.org/gradle/topics/customize-publish-task-to-upload-jar-to-maven-repo-per-build-variant](http://forums.gradle.org/gradle/topics/customize-publish-task-to-upload-jar-to-maven-repo-per-build-variant)
