Record some problems encountered when publishing open source libraries to JCenter

I tortured myself this weekend, how to publish the open source library to JCenter, and then encountered some problems in the process, I will share it here.

This article is based on the previous article: teach you the process of publishing an open source library to JCenter step by step and the problems encountered in the steps, so if you haven't read the previous article, you can go and see~

  1. Error:No service of type Factory

Reason: bug in android-maven-gradle-plugin plugin

Solution: Change the version, the problem version 1.3 is found in this test, and it is normal after changing to 1.4.1

Approach: Modify the plugin version in the build.gradle file in the root directory:

dependencies {
    classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'
}
  1. Error:Could not get unknown property 'publishedGroupId' for project ':tv' of type org.gradle.api.Project.

Reason: apply from ' https://raw.githubusercontent.com/nuuneoi/JCenter/master/installv1.gradle ' code is misplaced

Solution: Since the above apply from code means to use the script template file stored on the Internet, the template file uses many variables that have not been declared, so the apply from line of code should be placed after the ext {} variable declaration code block

Practice: The following lines of code in the build.gradle file should be in order. The first line of apply from: 'bintray-config.gradle' is actually the variable declaration and assignment code in the script template file, that is, the ext{} code block, Just put it in a gradle file alone, you can also replace the ext{} code directly with apply from: 'bintray-config.gradle'

apply from: 'bintray-config.gradle'
//ext{} 变量声明,赋值代码块必须在以下两个脚本模板文件之前
apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/installv1.gradle'
apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/bintrayv1.gradle'
  1. Error:Cause: android.compileSdkVersion is missing!

Reason: apply from: ' https://raw.githubusercontent.com/nuuneoi/JCenter/master/bintrayv1.gradle ' code is misplaced

Solution: Similar to reason 2, this script is used to upload locally generated pom, aar and other files to the bintray repository, but the operation of this script needs to depend on the attribute configuration of some android {} blocks; so not all apply from The code of 2 is placed at the beginning of build.gradle. It is recommended to place the three apply from codes in 2 at the end of the build.gradle file.

The above 1-3 problems are all in the steps in the previous article, step 2: configure the local gradle script plugin, which is caused by improper operation during the process

  1. Execution failed for task ':tv :javadoc.

Reason: gradlew installAn error occurred during execution. This is due to a problem in the process of generating javadoc during execution. As for why there is a problem, you can check the log specifically, for example, here:

GBKerror.png

I am here because there is Chinese in the code, so the build error caused

Solution: I don't know if there are other solutions, and I don't want to delete these Chinese comments, so I can only turn off the task of this javadoc, anyway, the open source library I uploaded to JCenter is only my own. Use, no javadoc documentation required

Approach: Since the task of javadoc is in the script template file provided by bintray, you can only modify this template file, then in the second step of the previous article: Configure the local gradle script plugin, you cannot use apply from 'http://...'the form, because this Forms cannot modify template files.

Then you need to create a new installv1.gradle file locally, and then copy the code in this script file into this new file:

//将下面所有的 javadoc task 注释掉,不用这个功能
apply plugin: 'com.jfrog.bintray'

version = libraryVersion

if (project.hasProperty("android")) { // Android libraries
    task sourcesJar(type: Jar) {
        classifier = 'sources'
        from android.sourceSets.main.java.srcDirs
    }

//1. 这里是第1处
//    task javadoc(type: Javadoc) {
//        source = android.sourceSets.main.java.srcDirs
//        classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
//    }
} else { // Java libraries
    task sourcesJar(type: Jar, dependsOn: classes) {
        classifier = 'sources'
        from sourceSets.main.allSource
    }
}

//2. 这里是第2处
//task javadocJar(type: Jar, dependsOn: javadoc) {
//    classifier = 'javadoc'
//    from javadoc.destinationDir
//}

artifacts {
//3. 这里是第3处
//    archives javadocJar
    archives sourcesJar
}

// Bintray
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())

bintray {
    user = properties.getProperty("bintray.user")
    key = properties.getProperty("bintray.apikey")
    println user
    println key

    configurations = ['archives']
    pkg {
        repo = bintrayRepo
        name = bintrayName
        desc = libraryDescription
        websiteUrl = siteUrl
        vcsUrl = gitUrl
        licenses = allLicenses
        publish = true
        publicDownloadNumbers = true
        version {
            desc = libraryDescription
            gpg {
                sign = true //Determines whether to GPG sign the files. The default is false
                passphrase = properties.getProperty("bintray.gpg.password")
                //Optional. The passphrase for GPG signing'
            }
        }
    }
}

Then at the end of the build.gradle file under module, replace the original apply from code with the following:

apply from: 'bintray-config.gradle'
apply from: 'bintrayv1.gradle'
apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/installv1.gradle'

The above two apply from refers to the use of local script files, and the last apply from refers to the use of script files on the network. The local script files can be modified by yourself.

  1. Some notes on the operation of the bintray website
  • QQ mailbox cannot be used when registering an account, it is recommended to use gmail mailbox
  • After creating the warehouse on bintray, I also created the package by the way. The package corresponds to a module in the local project. As for whether it is feasible to directly perform the upload operation locally without creating a package, I have not tested it.
  • In the code block of the ext {} variable declaration, which attribute values ​​can not be configured, I have not tested it, but I feel that it is better to configure each attribute according to the template.

QQ picture 20180316094923.jpg
Recently (2018-03) I just opened the official account. I want to motivate myself to keep writing. At the beginning, I mainly shared original Android or Android-Tv knowledge. The preparation may be a little insufficient. If you are interested, you can pay attention first. Thank you for your support~~

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325646148&siteId=291194637