Configure description for package published to the GitHub Packages Gradle registry - gradle

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

Related

gradle publish custom pom

I have written a gradle task which writes a custom pom to "build/libs/pom.xml"
I want to publish above custom pom.xml , so I defined :
def pomXml = artifacts.add('archives', file("$buildDir/libs/pom.xml")) {
builtBy('writePoms') // writePoms is my custom task to create custom pom.xml
}
publishing {
publications {
maven(MavenPublication) {
artifact pomXml
artifactId "myartifact"
groupId 'com.xyz'
version project.version
}
}
repositories {
// Task for manually publishing the maven image. When CI works, setup CI_TOKEN auth.
maven {
url <url>
name "GitLab"
credentials(HttpHeaderCredentials) {
name = System.getenv("CI_JOB_TOKEN") ? "Job-Token" : "Private-Token"
value = System.getenv("CI_JOB_TOKEN") ? System.getenv("CI_JOB_TOKEN") : gitLabPrivateToken
}
authentication {
header(HttpHeaderAuthentication)
}
}
}
When I run ./gradlew publish it publishes pom from "build/publications/maven/pom-default.xml" instead of "build/libs/pom.xml"
Can someone help how can I achieve it?
I had a similar issue (aggregate build of multiple external repositories with their own build systems and then publishing the results of those builds to a local artifactory).
I was able to effectively replace the generated POM for the "artifacts" publication with the content of an external POM via withXml:
pluginManager.withPlugin("maven-publish") {
extensions.configure(PublishingExtension::class.java) {
publications.register<MavenPublication>("artifacts") {
groupId = "com.example"
artifactId = "external"
version = "1.0.0"
artifact("external.jar")
pom.withXml {
asNode().setValue(XmlParser().parse("some/external/pom.xml").value())
}
}
}
}
This leaves the <xml ...> and <project ...> nodes intact (acceptable for my case).

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

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

How to consolidate imported plugins to custom plugin in Gradle using Kotlin

I have microservices that will share some of the same configuration between all of them, mainly Jib, publish, and release. Not sure if it's possible to do the same for dependencies but it would be beneficial to include actuator and log4j2 in each. Here is the build.gradle.kts for one of my projects.
import net.researchgate.release.BaseScmAdapter
import net.researchgate.release.GitAdapter
import net.researchgate.release.ReleaseExtension
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
id("com.gorylenko.gradle-git-properties") version "1.5.1"
id("com.google.cloud.tools.jib") version "1.6.1"
id("io.spring.dependency-management") version "1.0.7.RELEASE"
id("net.researchgate.release") version "2.8.1"
id("org.sonarqube") version "2.7.1"
id("org.springframework.boot") version "2.1.6.RELEASE"
kotlin("jvm") version "1.2.71"
kotlin("plugin.spring") version "1.2.71"
jacoco
`maven-publish`
}
java.sourceCompatibility = JavaVersion.VERSION_1_8
springBoot {
buildInfo {
group = project.properties["group"].toString()
version = project.properties["version"].toString()
description = project.properties["description"].toString()
}
}
repositories {
maven(url = uri(project.properties["nexus.url.gateway"].toString()))
mavenCentral()
}
dependencies {
// Kotlin
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
// Spring
implementation("org.springframework.boot:spring-boot-starter-actuator")
implementation("org.springframework.boot:spring-boot-starter-log4j2")
implementation("org.springframework.boot:spring-boot-starter-security")
implementation("org.springframework.cloud:spring-cloud-config-server")
testImplementation("org.springframework.boot:spring-boot-starter-test")
}
dependencyManagement {
imports {
mavenBom("org.springframework.cloud:spring-cloud-dependencies:Greenwich.SR3")
}
}
configurations.all {
exclude(group = "ch.qos.logback", module = "logback-classic")
exclude(group = "org.springframework.boot", module = "spring-boot-starter-logging")
}
tasks {
withType<KotlinCompile> {
kotlinOptions {
freeCompilerArgs = listOf("-Xjsr305=strict")
jvmTarget = "1.8"
}
}
build { dependsOn(clean) }
afterReleaseBuild { dependsOn(publish) }
publish { dependsOn(build) }
jibDockerBuild { dependsOn(build) }
jacocoTestReport {
reports {
html.isEnabled = false
xml.isEnabled = true
}
}
}
publishing {
publications {
create<MavenPublication>(project.name) {
from(components["java"])
pom {
scm {
connection.set("scm:git:git#github.com:company/${project.name}.git")
developerConnection.set("scm:git:git#github.com:company/${project.name}.git")
url.set("https://github.com/company/${project.name}/")
}
}
versionMapping {
usage("java-api") {
fromResolutionOf("runtimeClasspath")
}
usage("java-runtime") {
fromResolutionResult()
}
}
}
}
repositories {
maven {
val releasesRepoUrl = "${project.properties["nexus.url.publish"].toString()}/releases"
val snapshotsRepoUrl = "${project.properties["nexus.url.publish"].toString()}/snapshots"
url = uri(if (version.toString().endsWith("SNAPSHOT")) snapshotsRepoUrl else releasesRepoUrl)
credentials {
username = project.properties["nexus.user"].toString()
password = project.properties["nexus.password"].toString()
}
}
}
}
fun ReleaseExtension.git(configureFn : GitAdapter.GitConfig.() -> Unit) {
(propertyMissing("git") as GitAdapter.GitConfig).configureFn()
}
release {
scmAdapters = mutableListOf<Class<out BaseScmAdapter>> ( GitAdapter::class.java )
git {
requireBranch = "develop"
pushToRemote = project.properties["release.git.remote"].toString()
pushReleaseVersionBranch = "master"
tagTemplate = "${project.name}.${project.version}"
}
}
jib {
from {
image = "openjdk:8-jdk-alpine"
}
to {
image = "host:port/${project.name}:${project.version}"
auth {
username = project.properties["nexus.user"].toString()
password = project.properties["nexus.password"].toString()
}
}
container {
workingDirectory = "/"
ports = listOf("8080")
environment = mapOf(
"SPRING_OUTPUT_ANSI_ENABLED" to "ALWAYS",
"SPRING_CLOUD_BOOTSTRAP_LOCATION" to "/path/to/bootstrap.yml"
)
useCurrentTimestamp = true
}
setAllowInsecureRegistries(true)
}
I was able to get a custom plugin created and added to this project using git#github.com:klg71/kotlintestplugin.git and git#github.com:klg71/kotlintestpluginproject.git but I have no idea how to implement these existing plugins and their configurations. In the main Plugin class in the apply function I am able to call the project.pluginManager.apply(PublishingPlugin::class.java) which causes the task to show in the project referencing the custom plugin but I can't figure out how to configure it and it does not successfully publish to the nexus server. I can publish the plugin itself to the nexus server and reference it in the microservice but it skips running the task, which I assume is caused by the configuration not being included. Also, when trying to apply/configure the Jib plugin, all of the classes are not visible when attempting to import.
So the above answer isn't super long and to preserve the issues I ran into I am posting a new answer.
PLUGIN
This portion of the answer is going to discuss the actual custom plugin project.
Because the plugins wrapper in the build.gradle.kts is runtime, the CustomPlugin.kt does not have access to it at compile time. My boss who is much smarter than me was kind enough to point this out to me even though he has never worked with gradle. Although I looked pretty dumb in front of him he still got me up and running by basically following the 'legacy' way of applying plugins in gradle.
plugins { // This is a runtime script preventing plugins declared here to be accessible in CustomPlugin.kt but is used to actually publish/release this plugin itself
id("net.researchgate.release") version "2.8.1"
kotlin("jvm") version "1.3.0"
`maven-publish`
}
repositories {
maven { url = uri("https://plugins.gradle.org/m2/") } // This is required to be able to import plugins below in the dependencies
jcenter()
}
dependencies {
compile(kotlin("stdlib"))
compile(kotlin("reflect"))
// These must be declared here (at compile-time) in order to access in CustomPlugin.kt
compile(group = "gradle.plugin.com.gorylenko.gradle-git-properties", name = "gradle-git-properties", version = "2.2.0")
compile(group = "gradle.plugin.com.google.cloud.tools", name = "jib-gradle-plugin", version = "1.7.0")
compile(group = "net.researchgate", name = "gradle-release", version = "2.8.1")
compile(group = "org.asciidoctor", name = "asciidoctor-gradle-plugin", version = "1.5.9.2")
compile(group = "org.jetbrains.dokka", name = "dokka-gradle-plugin", version = "0.9.18")
compile(group = "org.sonarsource.scanner.gradle", name = "sonarqube-gradle-plugin", version = "2.8")
implementation(gradleApi()) // This exposes the gradle API to CustomPlugin.kt
}
This allowed me to have access to jib and everything else in the CustomPlugin.kt.
The plugins jacoco and maven-publish are automatically accessible in the plugin project but still need to be added in the microservice project referencing the plugin. I was unable to find a workaround for this unfortunately.
I included the typical maven-publish plugin in the build.gradle.kts to push to nexus with the publishing task configurations in the build.gradle.kts as well so I could pull this from nexus in the microservice that wanted to use the plugin.
publishing {
publications {
create<MavenPublication>(project.name) {
from(components["java"])
pom {
scm {
connection.set("scm:git:git#github.com:diendanyoi54/${project.name}.git")
developerConnection .set("scm:git:git#github.com:diendanyoi54/${project.name}.git")
url.set("https://github.com/diendanyoi54/${project.name}/")
}
}
}
}
repositories {
maven {
val baseUrl = "https://${project.properties["nexus.host"].toString()}:${project.properties["nexus.port.jar"].toString()}/repository"
url = uri(if (version.toString().endsWith("SNAPSHOT")) "$baseUrl/maven-snapshots" else "$baseUrl/maven-releases")
credentials {
username = project.properties["nexus.user"].toString()
password = project.properties["nexus.password"].toString()
}
}
}
}
Lastly, you want to make sure you include the properties file that will tell the microservices where the plugin class is. In Intellij's IDEA, when typing the path to the implementation-class it auto completed for me.
The name of this file should reflect apply(plugin = "string") in the microservice's build.gradle.kts.
IMPLEMENTATION
This portion of the answer is going to reflect the microservice project that will be referencing the plugin. As stated above, jacoco and maven-publish still need to be added to the plugin block in the build.gradle.kts for some reason (I think because they are official gradle plugins).
To reference the plugin from the nexus server it was published to, the microservice must reference it in the buildscript.
buildscript { // Custom plugin must be accessed by this buildscript
repositories {
maven {
url = uri("https://${project.properties["nexus.host"].toString()}:${project.properties["nexus.port.jar"].toString()}/repository/maven-public")
credentials {
username = project.properties["nexus.user"].toString()
password = project.properties["nexus.password"].toString()
}
}
}
dependencies { classpath("com.company:kotlin-consolidated-plugin:1.0.0-SNAPSHOT") }
}
Lastly, the plugin must be applied using the properties file name referenced above.
apply(plugin = "com.company.kotlinconsolidatedplugin") // Custom plugin cannot reside in plugin declaration above
I created sample projects of these and posted them to Github so feel free to clone or take a look:
git#github.com:diendanyoi54/kotlin-consolidated-plugin.git
git#github.com:diendanyoi54/kotlin-consolidated-plugin-implementation.git
I was able to successfully able to use the github repo examples referenced above to accomplish what I needed with the publish task. Here is my custom plugin's build.gradle.kts.
plugins {
id("com.google.cloud.tools.jib") version "1.6.1"
id("org.sonarqube") version "2.7.1"
kotlin("jvm") version "1.3.0"
`maven-publish`
}
dependencies {
compile(kotlin("stdlib"))
compile(kotlin("reflect"))
implementation(gradleApi())
}
repositories {
jcenter()
}
publishing {
publications {
create<MavenPublication>(project.name) {
from(components["java"])
pom {
scm {
connection.set("scm:git:git#github.com:company/${project.name}.git")
developerConnection.set("scm:git:git#github.com:company/${project.name}.git")
url.set("https://github.com/company/${project.name}/")
}
}
}
}
repositories {
maven {
val baseUrl = "https://${project.properties["nexus.host"].toString()}:${project.properties["nexus.port.jar"].toString()}/repository"
url = uri(if (version.toString().endsWith("SNAPSHOT")) "$baseUrl/maven-snapshots" else "$baseUrl/maven-releases")
credentials {
username = project.properties["nexus.user"].toString()
password = project.properties["nexus.password"].toString()
}
}
}
}
Here is the CustomPlugin.kt class.
package com.company.gradlemicroserviceplugin
//import com.google.cloud.tools.jib.gradle.JibExtension
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.publish.PublishingExtension
import org.gradle.api.publish.maven.MavenPublication
import org.gradle.api.publish.plugins.PublishingPlugin
import org.gradle.testing.jacoco.tasks.JacocoReport
import java.net.URI
open class CustomPlugin : Plugin<Project> {
override fun apply(project: Project) {
// applySonar(project)
applyPublish(project)
// applyJib(project)
}
// private fun applySonar(project: Project) {
// project.pluginManager.apply("sonarqube")
// val task = project.task("jacocoTestReport") as JacocoReport
// task.reports = JacocoReport()
// jacocoTestReport { This was nested in the tasks declaration in build.gradle.kts so the fields below are the fields I'm trying to set in task.reports
// reports {
// html.isEnabled = false
// xml.isEnabled = true
// }
// }
// }
private fun applyPublish(project: Project) {
project.pluginManager.apply(PublishingPlugin::class.java)
val publishingExtension = project.extensions.findByType(PublishingExtension::class.java)
val mavenPublication = publishingExtension?.publications?.create(project.name, MavenPublication::class.java)
publishingExtension?.repositories?.maven {
val baseUrl = "https://${project.properties["nexus.host"].toString()}:${project.properties["nexus.port.jar"].toString()}/repository"
it.url = URI(if (project.version.toString().endsWith("SNAPSHOT")) "$baseUrl/maven-snapshots" else "$baseUrl/maven-releases")
it.credentials { cred ->
cred.username = project.properties["nexus.user"].toString()
cred.password = project.properties["nexus.password"].toString()
}
}
mavenPublication?.from(project.components.findByName("java"))
mavenPublication?.pom?.scm {
it.connection.set("scm:git:git#github.com:company/${project.name}.git")
it.developerConnection.set("scm:git:git#github.com:company/${project.name}.git")
it.url.set("https://github.com/company/${project.name}/")
}
}
// private fun applyJib(project: Project) {
// project.pluginManager.apply(JibPlugin::class.java)
//
// }
}
There are definitely areas of improvement on this but at least I got something working here. There is maven-publish logic in both build.gradle.kts because I push to the custom plugin to nexus and the maven-publish logic is in the CustomPlugin.kt class so the microservice that references this plugin can use it. However, I am unable to successfully setup Jib and Sonar. Jib doesn't give me access to anything in com.google.cloud.tools.jib.gradle preventing me from using the same approach as I used in maven-publish.
For Sonar I think I'm on the right track with retrieving the task by its name but I'm unable to set any fields that belong to task.reports because they are all final and this is necessary for Sonar to properly analyze Kotlin.
Applying built-in plugins
plugins {
java
id("jacoco")
}
You can also use the older apply syntax:
apply(plugin = "checkstyle")
Applying external plugins
plugins {
id("org.springframework.boot") version "2.0.1.RELEASE"
}
i am not good in kotlin but here is link to better understanding missing migration guide to the Gradle Kotlin DSL

Confused about process to publish snapshots to BinTray

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/

Resources