Kotlin Gradle DSL - Precompiled script in buildSrc not working - gradle

I am using Gradle version 4.10.3 (need Android support) and am trying to put a test precompiled script into my buildSrc folder for use with various modules within the project. Here is my basic code setup:
//maven-deploy.gradle.kts, a custom precompiled plugin under
// buildSrc\src\main\kotlin\maven-deploy.gradle.kts
plugins {
maven
signing
}
//a test task
tasks {
register("hello") {
doLast {
println("hello")
}
}
}
//buildSrc build.gradle.kts
plugins {
`kotlin-dsl`
`kotlin-dsl-precompiled-script-plugins`
}
repositories {
jcenter()
}
//main project root's build.gradle.kts
plugins {
base
kotlin("jvm") version Vof.kotlin apply false
kotlin("android") version Vof.kotlin apply false
kotlin("android.extensions") version Vof.kotlin apply false
id("kotlinx-serialization") version Vof.kotlin apply false
id("maven-deploy")
}
and I'm getting this error:
error:Plugin [id: 'maven-deploy'] was not found in any of the following sources:
- Gradle Core Plugins (not a core plugin, please see https://docs.gradle.org/4.10.3/userguide/standard_plugins.html for available core plugins)
- Plugin Repositories (plugin dependency must include a version number for this source)
Am I doing this incorrectly? I am following this guide on the Gradle website. Is this outdated? Any help is appreciated!
EDIT: I got this working by adding java-gradle-plugin (with tildes) to the buildSrc's build.gradle.kts file under plugins. Not sure if that is the correct way to go about this, however.

Related

Gradle DSL support for "latest.integration" version

I'm developing a custom plugin for gradle.
There is need to use latest version of plugin and it's already works with legacy gradle plugin application:
//build.gradle
buildscript {
...
dependencies {
classpath 'com.something:myPlugin:latest.integration'
}
...
}
apply plugin: com.something.my-plugin
Now I want to update my build script to use Gradle DSL, but it says that gradle cannot resolve "latest.integration" version for my plugin:
//setting.gradle
pluginManagement {
...
plugins {
id 'com.something.my-plugin' version "latest.integration"
}
...
}
//build.gradle
plugins {
id 'com.something.my-plugin'
}
Do anybody have a suggestion what I need to do? Or how I need to publish my plugin to support it?

Gradle precompiled script plugin: External Quarkus plugin dependency not found

Background
I am currently developing a gradle multi-project with multiple quarkus microservices. In order to bundle my quarkus dependencies I use a precompile script plugin with kotlin-dsl. Given the configuration below, executing quarkusBuild works fine.
Problem
Executing the quarkusDev task for a microservice subproject fails with
Unable to find quarkus-gradle-plugin dependency in project ':microservice'
Do you have any idea why this happens? I have put hours into this and I still do not see why it fails. https://github.com/quarkusio/quarkus/issues/12509 seems to be related, but the suggested solution did not work for me. Any help is greatly appreciated!
Edit
I realize there might be a difference between gradle.plugin.io.quarkus:quarkus-gradle-plugin:2.2.3.Final and io.quarkus:gradle-application-plugin:2.2.3.Final, but swapping the dependencies doesnt help much.
Configuration
This is a minimal version of my project which allows to reproduce the error.
This minimal example can also be checked out here: https://github.com/lorenzjosten/gradle-plugin-quarkus
rootProject
- buildSrc
- src/main/kotlin
quarkus-conventions.gradle.kts
build.gradle.kts
settings.gradle.kts
gradle.properties
- microservice
- src/...
build.gradle.kts
build.gradle.kts
settings.gradle.kts
gradle.properties
rootProject/buildSrc/src/main/kotlin/quarkus-conventions.gradle.kts
plugins {
java
id("io.quarkus")
}
val quarkusUniverseBomVersion: String by project
dependencies {
implementation(enforcedPlatform("io.quarkus:quarkus-universe-bom:$quarkusUniverseBomVersion"))
implementation("io.quarkus:quarkus-kotlin")
implementation("io.quarkus:quarkus-resteasy-reactive")
implementation("io.quarkus:quarkus-resteasy-reactive-jackson")
implementation("io.quarkus:quarkus-hibernate-reactive-panache")
implementation("io.quarkus:quarkus-reactive-pg-client")
implementation("io.quarkus:quarkus-smallrye-reactive-messaging-amqp")
implementation("io.quarkus:quarkus-arc")
testImplementation("io.quarkus:quarkus-junit5")
}
rootProject/buildSrc/build.gradle.kts
val quarkusPluginVersion: String by project
plugins {
`kotlin-dsl`
}
repositories {
mavenCentral()
maven("https://plugins.gradle.org/m2/")
gradlePluginPortal()
}
dependencies {
implementation("io.quarkus:gradle-application-plugin:${quarkusPluginVersion}")
}
rootProject/buildSrc/gradle.properties
quarkusPluginVersion=2.3.0.Final
rootProject/microservice/build.gradle.kts
plugins {
id("quarkus-conventions")
}
rootProject/settings.gradle.kts
include("microservice")
rootProject/build.gradle.kts
plugins {
idea
}
repositories {
mavenCentral()
maven("https://plugins.gradle.org/m2/")
gradlePluginPortal()
}
allprojects {
apply(plugin = "idea")
idea {
module {
isDownloadSources = true
isDownloadJavadoc = true
}
}
}
rootProject/gradle.properties
quarkusUniverseBomVersion=2.2.3.Final
The Gradle plugin likely cannot find the Java dependency:
// https://mvnrepository.com/artifact/io.quarkus/quarkus-universe-bom
implementation("io.quarkus:quarkus-universe-bom:2.2.3.Final")
It was a bug that should be fixed with quarkus release version 2.4.CR1
See Github issues
https://github.com/quarkusio/quarkus/issues/20595
https://github.com/quarkusio/quarkus/issues/20531

Gradle Kotlin DSL multi project build with Java Modules

I'm creating a new project (using IntelliJ IDEA) that will be using:
Gradle as the build system
Kotlin DSL for build scripts
Java 9 modules for "organisation"
Kotlin as the primary language
I'm having problems setting up Gradle to properly build my project. Most examples I've found are for Groovy and not Kotlin DSL, and most only cover some of the features I want, but not all.
Right now I have two modules, core and lib, where the core module requires the lib module. My gradle build scripts are:
build.gradle.kts
plugins {
base
kotlin("jvm") version "1.3.41" apply false
}
subprojects {
afterEvaluate {
tasks.withType<JavaCompile> {
inputs.property("moduleName", extra["moduleName"])
options.compilerArgs.addAll(arrayOf("--module-path", classpath.asPath))
classpath = files()
}
}
repositories {
mavenCentral()
jcenter()
}
}
core/build.gradle.kts
extra.set("moduleName", "myproject.core")
plugins {
kotlin("jvm")
}
dependencies {
compile(kotlin("stdlib"))
compile(project(":networking"))
}
lib/build.gradle.kts
extra.set("moduleName", "myproject.lib")
plugins {
kotlin("jvm")
}
dependencies {
compile(kotlin("stdlib"))
}
Doing this, configuration fails with:
A problem occurred configuring project ':core'.
Cannot get property 'moduleName' on extra properties extension as it does not exist
If I remove the inputs.property() line the configuration succeeds, but the core compilation fails (lib compiles successfully) with :
Task :core:compileKotlin
e: Module myproject.lib cannot be found in the module graph
I assume the issue is is my root build.gradle.kts, but I cannot figure out how to make it work. Googling around, Kotlin DSL for Gradle is somewhat new and not as widely used, and documentation is pretty scarce.
Any advice would be appreciated!
Naturally after posting the question I found the solution. There exists a Gradle plugin that does exactly what's needed in this situation, with a KotlinDSL example: https://github.com/java9-modularity/gradle-modules-plugin/tree/master/test-project-kotlin
Using the plugin, all I needed to do is change the root build.gradle.kts file:
plugins {
base
kotlin("jvm") version "1.3.41" apply false
id("org.javamodularity.moduleplugin") version "1.5.0" apply false
}
subprojects {
apply(plugin = "org.javamodularity.moduleplugin")
repositories {
mavenCentral()
jcenter()
}
}
Note: Make sure that your module-info.java file is in the java src folder, and not in the kotlin src folder, otherwise the plugin will not detect the module.

gradle-bintray-plugin Plugin [id: 'com.jfrog.bintray', version: '1.+'] was not found

I'm trying to use the gradle plugin gradle-bintray-plugin.
Currently using Gradle 4.4
Following the tutorial in the github page I should add the plugin in this way:
plugins {
...
id "com.jfrog.bintray" version "1.+"
}
I'm receiving this error message and not being able to continue:
Plugin [id: 'com.jfrog.bintray', version: '1.+'] was not found in any
of the following sources:
Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
Plugin Repositories (dynamic plugin versions are not supported) Open File
Dynamic versions were maybe authorized in the past for the plugins block (as the tutorial gives it as an example) but now it's forbidden
if (versionSelectorScheme.parseSelector(markerVersion).isDynamic()) {
result.notFound(SOURCE_NAME, "dynamic plugin versions are not supported");
return;
}
But it's not the case for the old buildscript way and the below code is working fine with Gradle 4.10
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.+'
}
}
I just find out the solution. Looks like it just works specifying the exact version that you want to use.
So changing this:
plugins {
...
id "com.jfrog.bintray" version "1.+"
}
To this:
plugins {
...
id "com.jfrog.bintray" version "1.8.4" // exact version!
}
Now Works!

Gradle: how to use the latest version of a plugin automatically

I have developed an internal plugin. The plugin has its own version. I then use that plugin for a build process in a repository.
If I change the version of the plugin, I have to update the build.gradle to spell our the new version. I have about 100 of these repositories.
Is there a way to specify in my build.gradle to use the latest version of the plugin that can be found in that location?
I could ran a batch file before gradle that find the latest, updates build.gradle with that number and then runs the build process but this is a big work around to a functionality that should be available.
See code below where I call the plugin that I change quite often:
buildscript {
repositories {
maven {
url "c:/git/_TEST/plug-in"
}
mavenCentral()
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath group: 'com.myplugin.gradle', name: 'com.myplugin.mypluginbuild', version: '1.0'
}
apply plugin: 'com.myplugin.mypluginbuild'
}
if I don't specify the version, it returns an error. Any suggestions?
For those who use plugins{} block, gradle7+ supports dynamic version, which includes + and latest.release.
plugins {
id "your-plugin-id" version "1.0.+"
}
dynamic version doc
It's not possible this way. See the plugins {} block and plugins documentation.
For core plugins you must not provide a version.
For community plugins you have to provide a version.
Maybe script plugins are way to go:
apply from: 'my_script_plugin.gradle'
I have a solution to this question.
The + specified in the version field will do the trick. It will enable gradle to use the latest plug-in automatically.
I.e:
dependencies {
classpath group: 'com.myplugin.gradle', name: 'com.myplugin.mypluginbuild', version: '1.+'
}

Resources