title: Gradle publishing error with android library plugin
body: <p>I get the following error when trying to publish an android library to a local repository that is defined in init.gradle.</p>
  
  <pre><code>&gt; Cannot configure the 'publishing' extension after it has been accessed.
  </code></pre>
  
  <p>I have defined my maven repositories in ~/.gradle/init.gradle so that they can be used in all of my projects.</p>
  
  <pre><code>allprojects {
  
      apply plugin: 'maven-publish'
  
      repositories.ext.mavenMyRepo = {
          repositories.maven { 
              name "MyRepoSnapshot"
              url "file:/home/me/mvn/snapshot"
          }
          repositories.maven { 
              name "MyRepoRelease"
              url "file:/home/me/mvn/release"
          }
      }
  
      publishing {
          publications {
              mavenMyRepo(MavenPublication) {
                  repositories.maven {
                      if(project.version.endsWith('-SNAPSHOT')) {
                          url "file:/home/me/mvn/snapshot"
                      } 
                      else {
                          url "file:/home/me/mvn/release"
                      }
                  }
              }
          }
      }
   }
  </code></pre>
  
  <p>In my project build.gradle:</p>
  
  <pre><code>apply plugin: 'com.android.library'
  apply plugin: 'maven-publish'
  
  archivesBaseName = 'my-android-lib'
  version = '1.0.0-SNAPSHOT'
  
  buildscript {
      repositories {
          jcenter()
      }
      dependencies {
          classpath 'com.android.tools.build:gradle:1.5.0'
      }
  }
  
  android {
      compileSdkVersion 20
      buildToolsVersion "23.0.2"
  }
  
  task jar(type: Jar, dependsOn: 'compileReleaseSources') {
      from 'build/intermediates/classes/release'
      manifest {
          attributes("Implementation-Version": version)
      }
  }
  
  repositories {
      mavenCentral()
  }
  
  dependencies {
      compile 'org.slf4j:slf4j-api:1.7.5'
  }
  
  task sourcesJar(type: Jar) {
      classifier "sources"
      from 'src/main/java'
  }
  
  publishing {
      publications {
          mavenMyRepo(MavenPublication) {
              pom.withXml {
                  asNode().appendNode('description', 'Android Library')
              }
              groupId 'my.group'
              artifactId archivesBaseName
              // from components.java
              artifact sourcesJar
          }
      }
  }
  </code></pre>
  
  <p>Everything is working fine when I do this with other 'java' only projects.  I have read other questions that suggest that the issue may be with the order of applying the plugins, but that doesn't seem to work.</p>
  
  <p>Does anyone know why the android plugin would cause this issue?</p>
  
  <p>P.S.  I am using gradle (v2.6) on the command line, not Android Studio.</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>I tried this solution: <a href="https://stackoverflow.com/a/32746509/1329791">https://stackoverflow.com/a/32746509/1329791</a></p>
  
  <p>The error went away, but now project.version is unspecified in the init script so the wrong repository is used.</p>