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:
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:
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?