Gradle kotlin dsl with jfrog artifactory plugin - disable publish build info - gradle

I'm trying to stop our Artifactory job from publishing any build info. According to the JFrog docs, setting publishBuildInfo = false should do that for me. However, if I try to set the property in our gradle kotlin dsl, I get the following error:
Could not set unknown property 'publishBuildInfo' for task ':artifactoryPublish' of type org.jfrog.gradle.plugin.artifactory.task.ArtifactoryTask.
Here is our build.gradle.kts file. I replaced everything that should be irrelevant by ...:
...
plugins {
...
id("com.jfrog.artifactory") version "4.24.20"
...
}
...
artifactory {
setContextUrl("someUrl")
...
publish(delegateClosureOf<org.jfrog.gradle.plugin.artifactory.dsl.PublisherConfig> {
repository(delegateClosureOf<groovy.lang.GroovyObject> {
...
})
defaults(delegateClosureOf<groovy.lang.GroovyObject> {
invokeMethod("publications", "mavenJava")
setProperty("publishPom", true)
setProperty("publishArtifacts", true)
setProperty("publishBuildInfo", false)
})
})
}

Use invokeMethod
configure<org.jfrog.gradle.plugin.artifactory.dsl.ArtifactoryPluginConvention> {
publish {
defaults {
invokeMethod("setPublishBuildInfo", false)
}
}
}
I got this from the deleted answer. Not sure why it was deleted since it worked and saved my life :)

One more from me. Had been struggling with turning off that PublisherBuildInfo via Kotlin DSL in gradle. The above mentioned method didn't quite work for me so I ended up with
clientConfig.publisher.isPublishBuildInfo = false inside artifactory block
which worked for id("com.jfrog.artifactory") version "4.28.1".
For example:
...
artifactory {
setContextUrl("https://-our-artifactory-url")
clientConfig.publisher.isPublishBuildInfo = false
publish(
delegateClosureOf<PublisherConfig> {
repository(
delegateClosureOf<GroovyObject> {
...

Related

Gradle disable javadoc except on deploy

I have enabled the javadoc for a project with
java {
withJavadocJar()
}
The problem with this is that the javadoc is built everytime the library is built. In my case, this takes several minutes. Is there a good way to make the javadoc only run on gradle deloy?
The following did the trick:
// Disables a task unless we're publishing something.
def disableUnlessPublishing(toDisable) {
toDisable.enabled = false
gradle.taskGraph.whenReady {
gradle.taskGraph.allTasks
.findAll { it.group == "publishing" }
.any { toDisable.enabled = true }
}
}
disableUnlessPublishing(tasks.javadocJar)
disableUnlessPublishing(tasks.javadoc)
disableUnlessPublishing(tasks.sourcesJar)

Using Avro to java plugin in gradle kotlin dsl

I've a java project that is built using gradle kotlin dsl.
Now I want to use gradle-avro-plugin like this https://github.com/davidmc24/gradle-avro-plugin#alternate-usage
In kotlin dsl I have written the same logic as below -
plugins {
java
id( "com.github.davidmc24.gradle.plugin.avro") version "1.0.0"
}
dependencies {
implementation ("org.apache.avro", "avro", "1.10.1")
}
val generateAvro = tasks.register<com.github.davidmc24.gradle.plugin.avro.GenerateAvroJavaTask>("generateAvro") {
source("src/avro")
this.setOutputDir(file("dest/avro"))
}
configure<org.gradle.api.tasks.compile.JavaCompile> {
this.source = fileTree(generateAvro)
}
The above code is returning below error when I run grade compileJava-
> * What went wrong:
Extension of type 'JavaCompile' does not exist. Currently registered extension types: [ExtraPropertiesExtension, DefaultArtifactPublicationSet, SourceSetContainer, ReportingExtension, JavaPluginExtension, JavaInstallationRegistry, JavaToolchainService, DistributionContainer, JavaApplication, DefaultAvroExtension]
How can I fix this error?
I had similar issues, what worked for me was:
plugins {
id("com.github.davidmc24.gradle.plugin.avro") version "1.2.0"
}
dependencies {
implementation("org.apache.avro:avro:1.10.1")
}
tasks.withType<com.github.davidmc24.gradle.plugin.avro.GenerateAvroJavaTask> {
setOutputDir(file("src/dest/dir/"))
}
The important thing is I did not registered a new task, just specified a new destination directory for each task with the type GenerateAvroJavaTask

Javadoc and --enable-preview

I am using Gradle 6.0.1 and JDK12 with preview features.
Having the following configuration to be able to compile, run and test:
tasks.withType(JavaCompile) {
options.compilerArgs += "--enable-preview"
}
tasks.withType(Test) {
jvmArgs += "--enable-preview"
}
tasks.withType(JavaExec) {
jvmArgs += '--enable-preview'
}
That works fine for all except javadoc generation that I defined as follows:
task generateJavadocs(type: Javadoc) {
source = sourceSets.main.allJava
options.jFlags("--enable-preview")
}
When running gradle generateJavadocs I receive compilation errors for the new switch expressions. Has anybody made it work with Javadoc?
I had faced the same problem with preview features of JDK 14 (and Gradle 6.3). This has worked for me:
javadoc.options {
addBooleanOption('-enable-preview', true)
addStringOption('-release', '14')
}
In your case, try:
task generateJavadocs(type: Javadoc) {
options {
addBooleanOption('-enable-preview', true)
addStringOption('-release', '12')
}
}
This answer enhances Manfred's answer and is for anybody who is trying to set the javadoc args using gradle's kotlin api. It took me awhile to figure out that access to addStringOption and addBooleanOption requires a cast.
tasks.withType<Javadoc> {
val javadocOptions = options as CoreJavadocOptions
javadocOptions.addStringOption("source", "14")
javadocOptions.addBooleanOption("-enable-preview", true)
}

Configure plugin in separate file using Kotlin DSL

to differenciate diferent plugins configurations, I use separate files.
For example:
./build.gradle.kts
./detekt.gradle.kts
./settings.gradle.kts
./module1
./module2
...
In the root build.gradle.kts I have this:
plugins {
id("io.gitlab.arturbosch.detekt") version DependencyVersion.Detekt
}
buildscript {
dependencies {
classpath(io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.1.1)
}
}
And to configure it I go to the detekt.gradle.kts and put:
apply(plugin = "io.gitlab.arturbosch.detekt")
detekt {
// configure
}
But detekt lambda is not found. Also tried with:
apply(plugin = "io.gitlab.arturbosch.detekt")
configure<io.gitlab.arturbosch.detekt.Detekt> {
// configure
}
But it doesn't find .Detekt.
With JaCoCo I haven't got any problems using the second approach, but it doesn't work with Detekt or SonarQube.
How can I configure plugins in a separate file?
Thanks.
Try something like below. I have declared a plugin "sonarqube" in my main gradle. I then apply the file sonar.gradle.kts towards the end of the build.gradle.kts file.
build.gradle.kts:
plugins {
id("org.sonarqube") version "2.8" apply false
}
...
apply(from="$rootDir/gradle/includes/sonar.gradle.kts")
gradle/includes/sonar.gradle.kts:
apply(plugin="org.sonarqube")
Using a setup like above, I can then run "gradle sonarqube"
I faced a similar issue. Everything that you need to do is to call
configure<io.gitlab.arturbosch.detekt.extensions.DetektExtension> {
// configure
}
More info, you can find here: https://docs.gradle.org/current/userguide/migrating_from_groovy_to_kotlin_dsl.html#configuring-plugins

gradle maven publish Pom using kotlin-dsl

I have a multiplatform kotlin library project that publishes to maven and have been updating to the kotlin 1.3 multiplatform model and kotlin-dsl
The previous groovy gradle script has a modifyPom block, and i found an example here. However as soon as I add
val modifyPom : Closure<*> by ext
modifyPom(closureOf<MavenPom> {
// pom code in here
})
I get the same result no matter what is in the pom data, which is that the call of the modifyPom groovy closure breaks the build with a very vague error:
Build file '<path>\build.gradle.kts' line: 47
Open File
In other words the line number of the call of modifyPom groovy Closure, but nothing about the actual error.
I am using Gradle 5.0. Any help appreciated.
So - in Groovy I had this block for configuring POMs, and it worked just fine:
project.publishing.publications.forEach { publication ->
publication.pom.withXml {
def root = asNode()
root.appendNode("name", "libui")
root.appendNode("description", "Kotlin/Native interop to libui: a portable GUI library")
root.appendNode("url", POM_SCM_URL)
root.children().last() + {
licenses {
license {
name "MIT License"
url POM_SCM_URL
distribution "repo"
}
}
developers {
developer {
id "msink"
name "Mike Sinkovsky"
email "msink#permonline.ru"
}
}
scm {
url POM_SCM_URL
connection POM_SCM_CONNECTION
developerConnection POM_SCM_DEV_CONNECTION
}
}
}
}
And how to convert it to Kotlin DSL?
Edit:
Well, was answered in https://github.com/JetBrains/kotlin-native/issues/2372
In Gradle Kotlin DSL it becomes:
project.publishing.publications.withType<MavenPublication>().forEach { publication ->
with(publication.pom) {
withXml {
val root = asNode()
root.appendNode("name", "libui")
root.appendNode("description", "Kotlin/Native interop to libui: a portable GUI library")
root.appendNode("url", POM_SCM_URL)
}
licenses {
license {
name.set("MIT License")
url.set(POM_SCM_URL)
distribution.set("repo")
}
}
developers {
developer {
id.set("msink")
name.set("Mike Sinkovsky")
email.set("msink#permonline.ru")
}
}
scm {
url.set(POM_SCM_URL)
connection.set(POM_SCM_CONNECTION)
developerConnection.set(POM_SCM_DEV_CONNECTION)
}
}
}
This problem was fixed by changing the definition of modifyPom to
val modifyPom : Closure<MavenPom> by ext
That fixed the original problem as posted, and the pom is now being modified. If anyone needs help, add a comment and hopefully I will notice

Resources