在参考郭霖大神的文章 再见JCenter,将你的开源库发布到MavenCentral上吧 发布项目到Maven时候出现一点问题,在此记录下:
发布步骤按照上文进行就可以了,在点击pulish发布时时候出现几点问题:
提示发布时没有找到兼容的插件
出现这个问题时,解决方法可能有以下几种:
build.gradle
中apply plugin: "com.vanniktech.maven.publish"
这一行移动到app下的build.gradle
app
模块下的build.gradle
中的apply plugin: 'com.android.application
修改为 apply plugin: 'com.android.library'
app
模块下defaultConfig'
的applicationId
gradle.properties
中GROUP=xxx
修改成与sonatype
上的Group ID一致,要注意大小写有区分,在此贴出项目中的完整代码:
项目根目录的build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = "1.5.20"
repositories {
google()
mavenCentral()
}
dependencies {
classpath "com.android.tools.build:gradle:4.0.2"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.vanniktech:gradle-maven-publish-plugin:0.17.0'
}
}
allprojects {
repositories {
google()
mavenCentral()
}
plugins.withId("com.vanniktech.maven.publish") {
mavenPublish {
sonatypeHost = "S01"
}
}
}
app目录下的build.gradle
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
android {
compileSdkVersion 30
buildToolsVersion "30.0.2"
defaultConfig {
minSdkVersion 23
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
kotlinOptions {
jvmTarget = 1.8
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.2.0-rc03'
implementation 'androidx.viewpager2:viewpager2:1.0.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'com.google.android.material:material:1.1.0'
}
apply plugin: "com.vanniktech.maven.publish"
gradle.properties
org.gradle.jvmargs=-Xmx2048m
android.useAndroidX=true
android.enableJetifier=true
kotlin.code.style=official
GROUP=com.guolindev.glance
POM_ARTIFACT_ID=glance
VERSION_NAME=1.0.0
POM_NAME=Glance
POM_DESCRIPTION=A simple and handy Android database debugging library.
POM_INCEPTION_YEAR=2020
POM_URL=https://github.com/guolindev/Glance/
POM_SCM_URL=https://github.com/guolindev/Glance/
POM_SCM_CONNECTION=scm:git:git://github.com/guolindev/Glance.git
POM_SCM_DEV_CONNECTION=scm:git:ssh://github.com/guolindev/Glance.git
POM_DEVELOPER_ID=guolindev
POM_DEVELOPER_NAME=Lin Guo
POM_DEVELOPER_URL=https://github.com/guolindev/
signing.keyId=密钥ID的后8位
signing.password=密钥密码
signing.secretKeyRingFile=私钥文件路径
mavenCentralUsername=Sonatype账号
mavenCentralPassword=Sonatype密码
systemProp.org.gradle.internal.publish.checksums.insecure=true