修改好的代码maven-publish.gradle文件:
apply plugin: 'maven-publish'
//上一层目录创建local.properties,里面放
//username=xxxx
//password=xxxx//上一层目录创建或者已有gradle.properties,里面添加
//myGroup.id=com.xxx.android
//maven.name=XXXMavenRelease
//maven.upload.url=https://maven.xxxx.com/repository/maven-releases/Properties properties = new Properties()
try {InputStream inputStream = file('../local.properties').newDataInputStream()properties.load(inputStream)
} catch (Throwable ignored) {ignored.printStackTrace()
}
//这三个参数要传到git中 所以放在gradle.properties
def moduleGroupId = findProperty('myGroup.id') //对应maven后台网站上的路径
def mavenName = findProperty('maven.name') //对应maven后台网站上的路径
def mavenUploadUrl = findProperty('maven.upload.url') //对应maven后台网站上的路径
//这2个私人,所以是本地的
def mavenUploadUsername = properties.getProperty('username')
def mavenUploadPassword = properties.getProperty('password')
def moduleArtifactId = nameandroid {publishing {singleVariant("release") {withSourcesJar()withJavadocJar()}}
}afterEvaluate {publishing {publications {release(MavenPublication) {from components.releasegroupId = moduleGroupIdartifactId = moduleArtifactIdversion = moduleVersion}}repositories {maven {name = mavenNameurl = mavenUploadUrlcredentials {username = mavenUploadUsernamepassword = mavenUploadPassword}}}}
}
以前,我们通常是通过
task sourceJar(type: Jar) {getArchiveClassifier().set('sources')from android.sourceSets.main.java.srcDirs
}artifact sourceJar
现在会报错了。提示generateMetadataFileForReleasPublication without declaring an explit or implicit dependency.