简体   繁体   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

I am the mantainer of the Java 8 java.time JSP tags library. 我是Java 8 java.time JSP标签库的管理员 I have little experience publishing libraries on my own. 我自己出版图书馆的经验很少。 For the publication of this library I did some research and ended with a gradle build script that you can check in GitHub . 对于该库的发布,我进行了一些研究,并以一个gradle构建脚本结尾,您可以在GitHub中检查该脚本。 The process is a bit clunky but it works in the end. 这个过程有点笨拙,但最终还是可以的。

There seem to be a general understanding that the jcenter() repository is gaining a lot of attention. 似乎已经大致了解到jcenter()存储库正在引起很多关注。 Probably because of android. 可能是因为android。 Anyway I saw an encouraging blog post and decided to give it a try and migrate that library to JCenter publishing insted of Maven Central. 无论如何,我看到了令人鼓舞的博客文章,并决定尝试一下,将该库迁移到由Maven Central安装的JCenter发布。 Should be easy. 应该很容易。

It is not, for me at least. 至少对我来说不是。 Probably my fault as my knowledge of Maven, artifacts and all that stuff is poor. 可能是我对Maven,工件和所有其他东西的了解不佳。 Anyway I gave it some hours of research and come up with a new gradle build to publish to my Bintray maven repository. 无论如何,我花了一些时间进行研究,并提出了一个新的gradle版本,可以发布到我的Bintray Maven存储库中。 Which, if I'm not wrong, is the first step towards publishing to JCenter. 如果我没记错的话,这是发布到JCenter的第一步。

This is what I have so far: 这是我到目前为止的内容:

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
            }
        }
    }
}

You can find the result of the latest publication on my public Bintray maven repository . 您可以在我的公共Bintray Maven存储库中找到最新出版物的结果。 You can compare it to the files for the same version currently available on Maven Central . 您可以将其与Maven Central中当前可用的相同版本的文件进行比较。

Congratulations if you are reading this so far, because I haven't formulated ANY question yet. 到目前为止,如果您尚未阅读任何内容,则表示祝贺。 Sorry about that. 对于那个很抱歉。

My questions: 我的问题:

Is the gradle build script correct and the proper/canonical way? gradle构建脚本是否正确以及正确/规范的方式? Given that the library is quite simple I found the build script huge and clunky. 鉴于该库非常简单,我发现构建脚本庞大而笨拙。 It is supposed to be easier and it even has a gradle plugin. 它应该更容易,甚至有一个gradle插件。 But the new script is longer than the maven central one. 但是新脚本比Maven中央脚本更长

What about the *.md5 and *.sha1 files? *.md5*.sha1文件呢? Will be generated by JCenter, Maven Central, the sync proces... or should I do it? 将由JCenter,Maven Central,同步过程生成...还是应该这样做?

There is some way of testing all these without publishing an actual version of the library given that there is no unpublish capabilities on the repositories? 鉴于存储库上没有未发布的功能,有某种方法可以测试所有这些而不发布库的实际版本? (and for a good reason, eh? leftpad anyone?). (并且有充分的理由,是吗?

First, great job figuring it out. 首先,要弄清楚它的出色工作。 It looks good and works good. 看起来不错,运作良好。

It's bigger than the other one not because you use Bintray instead of Central, but because you use maven-publish plugin instead of maven , and being more powerful, the config is a bit more verbose. 它比另一个更大,不是因为您使用了Bintray而不是Central,而是因为您使用了maven-publish插件而不是maven ,并且功能更强大,因此配置更加冗长。 You can use Bintray (and the bintray plugin) with both maven and maven-publish , whatever you prefer. 您可以将Bintray(和bintray插件)与mavenmaven-publish ,无论您喜欢什么。

Re testing it – you can always run a test build against your private repository (click in the Set Me Up button to get instructions on how to set up your Maven and/or Gradle to resolve from it). 重新测试–您始终可以针对您的私有存储库运行测试版本(单击“设置我”按钮以获取有关如何设置Maven和/或Gradle进行解析的说明)。

Another validation will be syncing to Maven Central. 另一个验证将同步到Maven Central。 It will fail if something is wrong with your package metadata. 如果您的软件包元数据有问题,它将失败。

Re md5 and sha1, we don't see a reason to store computable metadata as files on a modern distribution platform, but we send them to Maven Central when we sync. 关于md5和sha1,我们没有理由将可计算的元数据存储为现代分发平台上的文件,但是在同步时将它们发送到Maven Central。

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

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