Gradle DSL support for "latest.integration" version - gradle

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?

Related

Add Android plugin to gradle init script

I'm currently working on creating my own Gradle custom distribution and I want to add some default settings to all my Android projects. I tried to do this with the following init script:
initscript {
repositories {
mavenCentral()
google()
}
dependencies {
classpath "com.android.tools.build:gradle:7.1.1"
}
}
apply plugin: 'com.android.application'
gradle.allprojects {
android {
...
}
dependencies {
implementation 'junit:junit:4.12'
}
}
but with this I get Plugin with id 'com.android.application' not found. What am I missing here?
For gradle init script, you must use the fully qualified class name of the plugin instead of the id. So you will have to apply the plugin this way:
apply plugin: com.android.build.gradle.AppPlugin
Change the initscript to buildscript.
And also, does this build.gradle in root project/directy? Because you Android Gradle Plugin is applied in the gradle module not in the root.
So apply:
apply plugin: "com.android.application"
inside your module's build.gradle.
Make sure your Gradle version is compatible with your Android Gradle Plugin.
For more information you can follow the link below, if it helps you
plugin with id com.android.application not found

Gradle doesn't find plugins: org.jetbrains.kotlin.jvm and kotlin2js

I'm a beginner in gradle, using version 4.8.
Whatever I do , the plugins are never found. I get this error message:
Plugin [id: 'org.jetbrains.kotlin.jvm', version: '1.3.20'] was not found in any of the following sources:
Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
Plugin Repositories (could not resolve plugin artifact 'org.jetbrains.kotlin.jvm:org.jetbrains.kotlin.jvm.gradle.plugin:1.3.20')
Searched in the following repositories:
Gradle Central Plugin Repository
No matter how many repositories I add, it seems it is only looking in "Gradle Central Plugin Repository"
My gradle.build file:
buildscript {
repositories {
mavenCentral()
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.20"
classpath "org.jetbrains.kotlin.jvm:kotlin-gradle-plugin:1.3.20"
}
}
plugins {
id 'java'
id 'org.jetbrains.kotlin.jvm' version '1.3.20'
id 'kotlin2js' version '1.3.20'
}
Can you help me?
Try the following gradle.build configuration:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.20"
}
}
plugins {
id 'java'
}
apply plugin: 'kotlin2js'
repositories {
mavenCentral()
}
When you include the plugin by id, it seems Gradle wants to retrieve the plugin from the Gradle plugin portal, but the Kotlin plugin is not there, it's part of the buildscript dependency. Using it with the apply plugin works. You can also find a slightly different working example here.
I had similar problem because i forgot about proxy settings like systemProp.https.proxyHost and systemProp.http.proxyHost and etc. that was set in ~/.gradle/gradle.properties.
I fixed configuration and plugin was successfully dowlnloaded
Check gradle.properties and try to add correct proxy settings if you behind firewall or escape this settings if you not.
you need to add repository mavenCentral() to the buildscript dependencies.
for example: kotlin-gradle-plugin:1.3.20. also the documentation hints for that.
Go to your project and then to the Gradle script. In Gradle, Go to Setting.Gradle and change the Fist Bitray Url to https://plugins.gradle.org/m2/.

Kotlin Gradle DSL - Precompiled script in buildSrc not working

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.

How to apply plugin to allprojects with new Gradle plugins mechanism?

Before Gradle 2.1 I could apply plugin to all projects by using allProjects closure (by prevoisly resolving the jar, of course):
buildscript {
repositories {
jcenter()
}
dependencies {
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:3.0.1"
}
}
allprojects {
apply plugin: "com.jfrog.artifactory"
}
With new publishing mechanism it looks like the plugins closure can't be used inside allprojects:
allprojects {
plugins {
id "com.jfrog.artifactory" version "3.0.1"
}
}
fails with:
"Could not find method plugins() for arguments [build_xxxx_run_closure1_closure4#yyyyy] on root project"
What are the rules of using plugins closure? Is the plugin applied to current project only? If so, how can I apply it to all projects without repeating the plugins closure inside each build?
The new plugins {...} syntax cannot be used within a allprojects {...} or subprojects {...} closure. Additionally, it can only be used within build scripts (no script plugins, init scripts, etc). If you want to avoid having to apply the plugin to each project individually I'd suggest using the old notation. This is an issue the Gradle team is aware of and a solution will be introduced in future versions.
Update: Starting with Gradle 3.0 you can do this in a slightly modified way. You still have to explicitly use apply() but you no longer have to deal with all the buildscript { } nonsense to get the plugin on your classpath. This also allows you to conditionally apply plugins. Check out the Gradle 3.0 release notes for more information.
plugins {
id 'my.special.plugin' version '1.0' apply false
}
allprojects {
apply plugin: 'java'
apply plugin: 'my.special.plugin'
}

How to configure a plugin to depend on a specific version of gradle?

I am writing a set of Gradle plugins, but I want to control the specific versions of groovy and gradle that are used.
I don't want the plugins to depend on whatever versions of Gradle/Groovy are installed, like the following would do:
dependencies {
compile localGroovy()
compile gradleApi()
}
Another reason I don't want to use the local method - when you use a proper dependency specification, Gradle then knows about the source code for those libs and the IDE plugins can hookup the source automatically.
Below are the relevant sections of my build script:
allprojects { Project iProject ->
apply plugin: 'idea'
apply plugin: 'maven'
repositories {
jcenter()
}
}
subprojects { Project iProject ->
apply plugin: 'groovy'
dependencies {
compile 'org.codehaus.groovy:groovy-all:2.3.2'
}
}
project(':eclipsei2g') {
group = 'eclipsei2g'
version = '0.0.1-SNAPSHOT'
dependencies {
compile 'org.gradle:gradle-core:2.0'
}
}
project(':g2idea13') {
group = 'g2idea13'
version = '0.0.1-SNAPSHOT'
dependencies {
compile 'org.gradle:gradle-core:2.0'
compile 'org.gradle-plugins:gradle-ide:2.0'
}
}
When I run this I get an error resolving the gradle-ide dependency:
Could not resolve all dependencies for configuration ':g2idea13:compile'.
> Could not find org.gradle:gradle-ide:2.0.
Searched in the following locations:
http://jcenter.bintray.com/org/gradle/gradle-ide/2.0/gradle-ide-2.0.pom
http://jcenter.bintray.com/org/gradle/gradle-ide/2.0/gradle-ide-2.0.jar
Required by:
g2idea13:g2idea13:0.0.1-SNAPSHOT
There doesn't seem to be anything on the jcenter repository since 0.9 for the plugins stuff.
I also tried 'org.gradle:gradle-ide:2.0'.
Is this even how I should be doing this? Is there another way to specify a specific gradle version? Am I just using the wrong repository? I couldn't even get gradle-core to resolve on mavenCentral(). Is there an official Gradle repository somewhere that I should be using?
gradleApi() is the way to go. There isn't currently a public list of dependencies for Gradle plugins.

Resources