MeanwhileInHell
MeanwhileInHell

Reputation: 7053

Gradle single-project pluginManagement block not working (Kotlin DSL)

I need to change a multi-project build to a single-project build, as there is and only ever will be one project in this repo. Currently, in settings.gradle, I have a custom plugin repo that currently uses a pluginManagement block with resolutionStrategy and my list of repo's:

pluginManagement {
    resolutionStrategy {
        eachPlugin {
            if (requested.id.namespace == 'com.meanwhileinhell.plugin') {
                useModule('com.meanwhileinhell:gradle-plugin:1.0.0-SNAPSHOT')
            }
        }
    }

    repositories {
        mavenLocal()
        maven { url "https://repo.spring.io/milestone" }
        maven { url "https://plugins.gradle.org/m2/" }

        // Meanwhileinhell repo
        maven {
            url "s3://mvn.meanwhileinhell.com/releases"
            credentials(AwsCredentials) {
                accessKey s3_access_key
                secretKey s3_access_secret
            }
        }
    }

    plugins {
        ...
        ...
    }
}

However, deleting settings.gradle and moving this block into my build.gradle.kts (Kotlin DSL) seems to do nothing. I've tried wrapping in a

configurations {
    all {
        resolutionStrategy {
            eachPlugin {
                ...
            }
        }
    }
}

and also

settings {
    pluginManagement {
        resolutionStrategy {
            eachPlugin {
                ...
            }
        }
    }
}

I found a SO answer that used settingsEvaluated in order to get the settings object, but again this was a no go.

Currently my build.gradle.kts looks like this, without pulling any plugin in from my repo:

val springBootVersion: String by project

group = "com.meanwhileinhell.myapp"
version = "$version"

repositories {
    mavenCentral()
    mavenLocal()
    maven ("https://repo.spring.io/snapshot")
    maven ("https://repo.spring.io/milestone")
    maven ("https://plugins.gradle.org/m2/")

    maven {
        url = uri("s3://mvn.meanwhileinhell.com/releases")
        credentials(AwsCredentials::class) {
            accessKey = (project.property("s3_access_key") as String)
            secretKey = (project.property("s3_access_secret") as String)
        }
    }
}

plugins {
    base
    eclipse
    idea
    java
    id("io.spring.dependency-management") version "1.0.9.RELEASE"
    // Load but don't apply to root project
    id("org.springframework.boot") version "1.5.14.RELEASE" apply false
}

dependencies {
    ...
}

Whenever I try to add a plugin id like id("com.meanwhileinhell.plugin.hell2java") version "1.0.0-SNAPSHOT" I get an error that looks like it isn't even looking in my S3 location:

* What went wrong:
Plugin [id: 'com.meanwhileinhell.plugin.hell2java', version: '1.0.0-SNAPSHOT'] 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 'com.meanwhileinhell.plugin.hell2java:com.meanwhileinhell.plugin.hell2java.gradle.plugin:1.0.0-SNAPSHOT')
  Searched in the following repositories:
    Gradle Central Plugin Repository

Any help on this would be appreciated!

EDIT !!!! -----------------------

I've just found this in the Gradle docs: https://docs.gradle.org/current/userguide/plugins.html#sec:plugin_management

The pluginManagement {} block may only appear in either the settings.gradle file....

Looks like I'm going down the wrong way entirely, so will look into the initialisation script route.

Upvotes: 4

Views: 4445

Answers (1)

Bjørn Vester
Bjørn Vester

Reputation: 7598

I think you may have missed something about the file structure.

In the Groovy DSL, you have the following files:

  • build.gradle
  • settings.gradle
  • init.gradle

In the Kotlin DSL, you have the same files but with the .kts extension:

  • build.gradle.kts
  • settings.gradle.kts
  • init.gradle.kts

The Kotlin DSL doesn't differ to the Groovy DSL in where to put things. pluginManagement need to go in to the settings file, so for Kotlin that would be settings.gradle.kts. If you are in doubt, look at the documentation. For almost all code examples, you can switch between Groovy and Kotlin DSL to see how to do it (and which files they are supposed go to into).

Upvotes: 2

Related Questions