Confused about process to publish snapshots to BinTray - gradle

I want to investigate publishing Hibernate ORM jars to Bintray. However one requirement we have is to be able to publish snapshots, which I see Bintray now supports through this OJO repository. However, I am quite confused about how this is supposed to work after reading the documentation.
First, the documentation mentions that I should be able to request publishing to JCenter and at the same time be able to request to be able to publish snapshots. However, I see no such options: https://bintray.com/hibernate/artifacts/hibernate-orm
Secondly, after I get the account on OJO set up, what, if anything, do I need to do special with the Bintray/Gradle plugin?

After many trial and errors I've ended up with the following setup.
We use 2 different plugins for publishing:
snapshots and release publishing (using com.jfrog.artifactory) and
bintray-related activities (using com.jfrog.bintray) in gradle (in the project p6spy).
Relevant parts from the build.gradle file follow, please note the specifics of the project :
plugins {
...
// to publish !SNAPSHOTs to bintray and sync it to maven-central
// ./gradlew bintrayUpload
id 'com.jfrog.bintray' version '1.7.3'
// to publish SNAPSHOTs and !SNAPSHOTs to oss.jfrog.org
// ./gradlew artifactoryPublish
id 'com.jfrog.artifactory' version '4.5.2'
}
publishing {
publications {
maven(MavenPublication) {
from components.java
groupId project.group
artifactId project.archivesBaseName
version project.version
...
pom {
packaging 'jar'
withXml {
asNode().children().last() + {
def builder = delegate
// maven central publishing mandatories
builder.name project.name
builder.description description
builder.url 'https://github.com/p6spy/p6spy'
builder.licenses {
builder.license {
builder.name 'The Apache Software License, Version 2.0'
builder.url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
builder.distribution 'repo'
}
}
builder.scm {
builder.url 'http://github.com/p6spy/p6spy'
builder.connection 'scm:git:git://github.com/p6spy/p6spy.git'
builder.developerConnection 'scm:git:ssh://github.com:p6spy/p6spy.git'
}
builder.developers {
builder.developer {
builder.name 'Quinton McCombs'
builder.email 'quinton.mccombs#gmail.com'
}
builder.developer {
builder.name 'Peter Butkovic'
builder.email 'butkovic#gmail.com'
}
builder.developer {
builder.name 'Felix Barnsteiner'
builder.email 'felix.barnsteiner#isys-software.de'
}
}
// maven central publishing optionals
builder.issueManagement {
builder.system 'github'
builder.url 'https://github.com/p6spy/p6spy/issues'
}
builder.ciManagement {
builder.system 'Travis CI'
builder.url 'https://travis-ci.org/p6spy/p6spy'
}
}
}
}
}
}
}
// to publish SNAPSHOTs to http://oss.jfrog.org/oss-snapshot-local/
// and !SNAPSHOTs to http://oss.jfrog.org/oss-release-local/
artifactory {
contextUrl = 'https://oss.jfrog.org'
resolve {
repository {
repoKey = 'libs-release'
}
}
publish {
repository {
// The Artifactory repository key to publish to
// when using oss.jfrog.org the credentials are from Bintray.
if (project.version.endsWith("-SNAPSHOT")) {
repoKey = 'oss-snapshot-local'
} else {
repoKey = 'oss-release-local'
}
username = System.getenv('BINTRAY_USER')
password = System.getenv('BINTRAY_API_KEY')
}
defaults {
publications 'maven'
properties = [ 'bintray.repo': 'p6spy/maven', 'bintray.package': 'p6spy:p6spy', 'bintray.version': project.version.toString() ]
}
}
}
// to publish to bintray and later sync to maven-central
bintray {
user = System.getenv('BINTRAY_USER')
key = System.getenv('BINTRAY_API_KEY')
publications = ['maven']
// dryRun = true
// publish = true
pkg {
repo = 'maven'
name = 'p6spy:p6spy'
userOrg = group
desc = description
websiteUrl = 'https://github.com/p6spy/p6spy'
issueTrackerUrl = 'https://github.com/p6spy/p6spy/issues'
vcsUrl = 'https://github.com/p6spy/p6spy.git'
licenses = ['Apache-2.0']
publicDownloadNumbers = true
githubRepo = 'p6spy/p6spy'
githubReleaseNotesFile = 'docs/releasenotes.md'
version {
released = new Date()
name = project.version
vcsTag = "p6spy-${project.version}"
// Optional configuration for Maven Central sync of the version
mavenCentralSync {
sync = true //[Default: true] Determines whether to sync the version to Maven Central.
close = '1' //Optional property. By default the staging repository is closed and artifacts are released to Maven Central. You can optionally turn this behaviour off (by puting 0 as value) and release the version manually.
user = System.getenv('SONATYPE_USERNAME') //OSS user token: mandatory
password = System.getenv('SONATYPE_PASSWORD') //OSS user password: mandatory
}
}
}
}
UPDATE
Published:
snapshots are in: http://oss.jfrog.org/oss-snapshot-local/p6spy/p6spy/ (I just followed official docs: https://www.jfrog.com/confluence/display/RTF/Deploying+Snapshots+to+oss.jfrog.org)
releases end up in: http://oss.jfrog.org/oss-release-local/p6spy/p6spy/ and are later auto-synced to maven central: http://repo1.maven.org/maven2/p6spy/p6spy/

Related

Is it possible to disable publish sha1 and ivy artifacts when use gradle ivy-publish plugin?

I try to publish a rpm artifact to Nexus repository with gradle plugin ivy-publish (script code written below). Is it possible to disable publishing some additional artifacts (sha1, ivy files), automatically generated by plugin ivy-publish ?
I've already disabled publishing sha256 and sha512 artifacts with systemProp.org.gradle.internal.publish.checksums.insecure
Gradle version is 6.3.
publishing {
publications {
artifactDistribution(IvyPublication) {
module = project.name
revision = project.version
def publishingArtifactories = [
[filename: "build/distributions/${project.name}-${project.version}-${project.release}.i386.rpm", extension: "rpm"],
]
publishingArtifactories.each {
artifact (it.filename) {
if (it.extension) {
extension it.extension
}
}
}
}
}
repositories {
ivy {
credentials {
username repoUser
password repoPassword
}
url project.publishUrl
layout 'pattern', {
artifact '[organisation]/[module]/[revision]/[artifact]-[revision](-[classifier]).[ext]'
ivy '[organisation]/[module]/[revision]/[module]-[revision].ivy'
m2compatible = true
}
}
}
}

Configure description for package published to the GitHub Packages Gradle registry

When publishing a package to the GitHub Packages Gradle registry, the resulting package's description is empty.
Is it possible to set the package description via config?
I have the following (abridged) configuration in build.gradle.kts, I was assuming it would use pom.description or the repo's README.md as the description but that doesn't seem to be the case.
plugins {
`maven-publish`
}
publishing {
publications {
create<MavenPublication>("mavenJava") {
groupId = project.group.toString()
artifactId = rootProject.name
version = project.version.toString()
from(components["java"])
pom {
name.set("steam-webapi-kt")
description.set("Steam WebAPI wrapper in Kotlin and Ktor")
url.set("https://github.com/j4ckofalltrades/steam-webapi-kt")
}
}
}
repositories {
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/j4ckofalltrades/steam-webapi-kt")
credentials {
username = System.getenv("GITHUB_ACTOR")
password = System.getenv("GITHUB_TOKEN")
}
}
}
}
Sample package: https://github.com/j4ckofalltrades/steam-webapi-kt/packages/899640

Publish Snapshot to oss.jfrog.org with multiple modules fails with 403

I'm trying to publish a project with multiple modules to artifactory (oss.jfrog.org). When I run artifactoryPublish I get a 403 error but I know it's not a permissions issue because it works with a single module. It only fails trying publish multiple modules.
Some modules are aars and others are jars and all include sources. I can publish them all to Bintray, but can't publish to artifactory (for snapshots).
So the question is, how do I configure a multi-module project to publish snapshots to oss.jfrog.org.
I've figured out that if I change it to publish a single module and make the artifact name the same as the last part of the group, it works, but a different name doesn't work (gives 403 error).
So if group is com.example.foo I can publish foo.jar (com/example/foo/foo/1.0.0-SNAPSHOT/foo-1.0.0.jar). But I can't publish bar.jar (com/example/foo/bar/1.0.0-SNAPSHOT/bar.jar).
This gradle is included in every project's build.gradle
afterEvaluate {
publishing {
publications {
mavenPublication(MavenPublication) {
artifact sourcesJar
if (project.plugins.hasPlugin("com.android.library")) {
artifact("$buildDir/outputs/aar/${project.name}-debug.aar")
} else {
artifact("$buildDir/libs/${project.name}-${version}.jar")
}
groupId "com.example.foo"
artifactId project.name // changing this to "foo" works for a single project
version version
pom {
name.set(project.name)
url.set(POM_URL)
packaging POM_PACKAGING
version version
licenses {
license {
name.set(POM_LICENSE_NAME)
url.set(POM_LICENSE_URL)
}
}
developers {
developer {
name.set(POM_DEVELOPER)
}
}
scm {
url.set(POM_SCM_URL)
connection.set(POM_SCM_CONNECTION)
developerConnection.set(POM_SCM_DEV_CONNECTION)
}
}
}
}
}
bintray {
user = project.findProperty('bintrayUser') ?: System.getenv('BINTRAY_USER')
key = project.findProperty('bintrayApiKey') ?: System.getenv('BINTRAY_API_KEY')
configurations = ['archives']
publish = true
dryRun = true
pkg {
name = project.name
repo = BINTRAY_REPO
userOrg = BINTRAY_ORG
licenses = [POM_LICENSE_NAME]
vcsUrl = POM_SCM_URL
version {
name = project.name
released = new Date()
}
}
}
artifactory {
contextUrl = 'http://oss.jfrog.org'
publish {
repository {
repoKey = 'oss-snapshot-local'
username = project.findProperty('bintrayUser') ?: System.getenv('BINTRAY_USER')
password = project.findProperty('bintrayApiKey') ?: System.getenv('BINTRAY_API_KEY')
}
defaults {
publications('mavenPublication')
publishArtifacts = true
publishPom = true
}
}
resolve {
repoKey = 'jcenter'
}
}
}
Artifactory returns a 403 whenever you're trying to publish an artefact that already exists. In your case, if you've previously published snapshot artefacts from your multi module build, whenever you will try doing that again, you will get a 403. I know you can configure the user access to provide delete permissions to the account you are using to deploy, as indicated here. However, overwriting history is not considered a good practice.
Regarding renaming your groups and artefacts, I don't think that will provide a solution, as it's not your GAV coordinates that are the issue, but rather the fact that artefacts with matching GAV already exist.
If I may ask, why do you want to use SNAPSHOT artefacts? Can you not achieve the same behaviour with dynamic dependencies and dependency locking?

Publishing Maven artifact to artifactory with different artifact ID

New to Maven Publishing. Our team has started using Artifactory and I'm trying to figure out how to publish to it, but using a custom artifact ID. Here's the relevant part of my build.gradle file
def applicationName = 'example-api'
def applicationVersion = '1.0.0.1'
def group = 'com.example.api'
def archiveName = "${applicationName}##${applicationVersion}"
bootWar {
archiveFileName = "${archiveName}.war"
}
publishing {
publications {
mavenJava(MavenPublication) {
artifact(file("build/libs/${archiveName}.war"))
afterEvaluate {
artifactId archiveName
groupId group
version applicationVersion
}
}
}
}
artifactory {
contextUrl = "http://172.17.0.2:32447/artifactory"
publish {
repository {
repoKey = 'libs-release-local'
username = 'admin'
password = 'password1'
maven = true
}
defaults {
publications('mavenJava')
publishBuildInfo = true
publishArtifacts = true
publishPom = false
}
}
clientConfig.info.setBuildName(applicationName)
clientConfig.info.setBuildNumber(applicationVersion)
}
But it seems it's never keeps the same name as the WAR file that's produced in the build. This is the closest I've gotten:
Ideally, I'd like to have the artifact be called just 'example-api##1.0.0.1.war' since it will be deployed to Tomcat.
When I try to remove groupId, Artfactory seems unable to create a repo URL, and if I omit the the version, the artifact name is then example-api##1.0.0.1-unspecified.war
Any thoughts?
What you see is the expected behaviour.
Maven artifact names are strictly <artifactId>-<version>.<extension>.
So when you set the publication configuration as follows:
artifactId = example-api##1.0.0.1
version = 1.0.0.1
extension = war
It results in an artifact named example-api##1.0.0.1-1.0.0.1.war
I would strongly recommend dropping the version from the artifactId part, to be better aligned with Maven conventions.
An alternative would be to use an Ivy repository, which has more flexibility around specifying the artifact name.

how to write project information in gradle?

I am converting a sample maven project to Gradle. In the maven project, there are tags like licenses, organization, developers. I just want to give these details in Gradle project. I have tried to add the following in build.gradle file,
licenses {
license {
name = 'Apache 1'
url = 'http://www.apache.org/licenses/LICENSE-1.0.txt'
distribution = 'repo'
comments = 'OSS license'
}
}
organization {
name = 'Sonatype'
url = 'http://www.sonatype.com'
}
but it gives an error.
> Could not find method licenses() for arguments [build_aa7z0myalt7c30hobty4ylab$_run_closure1#227a2f2] on root project 'simple-weather' of type org.gradle.api.Project.
How to do the same, Whether I have to add some plugin?
Customizing the POM published to Maven repositories is up to the maven-publish plugin.
Example:
plugins {
id 'maven-publish'
}
publishing {
publications {
mavenJava(MavenPublication) {
pom {
licenses {
license {
name = 'Apache 1'
url = 'http://www.apache.org/licenses/LICENSE-1.0.txt'
distribution = 'repo'
comments = 'OSS license'
}
}
organization {
name = 'Sonatype'
url = 'http://www.sonatype.com'
}
}
}
}
}

Resources