繁体   English   中英

如何迁移gradle发布脚本以将OSS库发布到Bintray的JCenter而不是Sonatype的Maven Central

[英]How to migrate gradle publication script to publish OSS library to Bintray's JCenter instead of Sonatype's Maven Central

我是Java 8 java.time JSP标签库的管理员 我自己出版图书馆的经验很少。 对于该库的发布,我进行了一些研究,并以一个gradle构建脚本结尾,您可以在GitHub中检查该脚本。 这个过程有点笨拙,但最终还是可以的。

似乎已经大致了解到jcenter()存储库正在引起很多关注。 可能是因为android。 无论如何,我看到了令人鼓舞的博客文章,并决定尝试一下,将该库迁移到由Maven Central安装的JCenter发布。 应该很容易。

至少对我来说不是。 可能是我对Maven,工件和所有其他东西的了解不佳。 无论如何,我花了一些时间进行研究,并提出了一个新的gradle版本,可以发布到我的Bintray Maven存储库中。 如果我没记错的话,这是发布到JCenter的第一步。

这是我到目前为止的内容:

plugins {
    id "com.jfrog.bintray" version "1.6"
}

apply plugin: 'java'
apply plugin: 'maven-publish'

group = 'net.sargue'
version = '1.1.2'

sourceCompatibility = 1.8
compileJava.options.encoding = 'UTF-8'
compileTestJava.options.encoding = 'UTF-8'

repositories {
    jcenter()
}

configurations {
    testCompile.extendsFrom compileOnly
}

dependencies {
    compileOnly 'javax.servlet:javax.servlet-api:3.0.1'
    compileOnly 'javax.servlet.jsp:javax.servlet.jsp-api:2.2.1'
    compileOnly 'javax.servlet.jsp.jstl:javax.servlet.jsp.jstl-api:1.2.1'

    testCompile 'junit:junit:4.12'
    testCompile 'org.springframework:spring-test:4.1.7.RELEASE'
}

jar {
    manifest {
        attributes 'Implementation-Title': 'Java 8 java.time JSP tags',
                   'Implementation-Version': version
    }
}

task javadocJar(type: Jar) {
    classifier = 'javadoc'
    from javadoc
}

task sourcesJar(type: Jar) {
    classifier = 'sources'
    from sourceSets.main.allSource
}

publishing {
    publications {
        MyPublication(MavenPublication) {
            from components.java
            artifact sourcesJar
            artifact javadocJar
            artifactId 'java-time-jsptags'

            pom.withXml {
                asNode().children().last() + {
                    resolveStrategy = Closure.DELEGATE_FIRST

                    name 'Java 8 java.time JSP tags'
                    description 'JSP tag support for Java 8 java.time (JSR-310)'
                    url 'https://github.com/sargue/java-time-jsptags'

                    scm {
                        connection 'scm:git:git@github.com:sargue/java-time-jsptags.git'
                        developerConnection 'scm:git:git@github.com:sargue/java-time-jsptags.git'
                        url 'git@github.com:sargue/java-time-jsptags.git'
                    }

                    licenses {
                        license {
                            name 'The Apache License, Version 2.0'
                            url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
                        }
                    }

                    developers {
                        developer {
                            id 'sargue'
                            name 'Sergi Baila'
                            email 'sargue@gmail.com'
                        }
                    }
                }
            }
        }
    }
}

bintray {
    user = BINTRAY_USER
    key = BINTRAY_KEY
    publications = ['MyPublication']
    pkg {
        repo = 'maven'
        name = 'java-time-jsptags'
        licenses = ['Apache-2.0']
        vcsUrl = 'https://github.com/sargue/java-time-jsptags.git'
        version {
            name = project.version
            desc = 'Java 8 java.time JSP tags'

            gpg {
                sign = true
                passphrase = BINTRAY_GPG
            }
        }
    }
}

您可以在我的公共Bintray Maven存储库中找到最新出版物的结果。 您可以将其与Maven Central中当前可用的相同版本的文件进行比较。

到目前为止,如果您尚未阅读任何内容,则表示祝贺。 对于那个很抱歉。

我的问题:

gradle构建脚本是否正确以及正确/规范的方式? 鉴于该库非常简单,我发现构建脚本庞大而笨拙。 它应该更容易,甚至有一个gradle插件。 但是新脚本比Maven中央脚本更长

*.md5*.sha1文件呢? 将由JCenter,Maven Central,同步过程生成...还是应该这样做?

鉴于存储库上没有未发布的功能,有某种方法可以测试所有这些而不发布库的实际版本? (并且有充分的理由,是吗?

首先,要弄清楚它的出色工作。 看起来不错,运作良好。

它比另一个更大,不是因为您使用了Bintray而不是Central,而是因为您使用了maven-publish插件而不是maven ,并且功能更强大,因此配置更加冗长。 您可以将Bintray(和bintray插件)与mavenmaven-publish ,无论您喜欢什么。

重新测试–您始终可以针对您的私有存储库运行测试版本(单击“设置我”按钮以获取有关如何设置Maven和/或Gradle进行解析的说明)。

另一个验证将同步到Maven Central。 如果您的软件包元数据有问题,它将失败。

关于md5和sha1,我们没有理由将可计算的元数据存储为现代分发平台上的文件,但是在同步时将它们发送到Maven Central。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM