Skip to content
This repository has been archived by the owner on Aug 19, 2020. It is now read-only.

How to use closures? #1408

Open
antonalechnovic opened this issue Jun 14, 2020 · 2 comments
Open

How to use closures? #1408

antonalechnovic opened this issue Jun 14, 2020 · 2 comments

Comments

@antonalechnovic
Copy link

antonalechnovic commented Jun 14, 2020

I am trying to convert the following groovy snippet to Kotlin:

class CustomPlugin implements Plugin<Project> {
    void apply(Project target) {
        target.apply plugin: 'com.jfrog.artifactory'
        target.artifactory {
            contextUrl = "http://some/artifactory/"
        }

}

How to set target.artifactory.contextUrl and remaining parameters?

I want to configure simillarly to build.gradle :

artifactory {
   contextUrl ="someUrl"
    publish {
        repository {
            repoKey = "some"
            username = "someUsername"
            password = "somePassword"
        }
}
@StefMa
Copy link
Contributor

StefMa commented Jun 14, 2020

You can apply the plugin with the PluginManager.
You can get an instance from it from the Project.

The "closure" is an Gradle extension. Get an instance of it with project.extensions.getByType(ClassOfTheExtension::java:class).
You can simply set the properties on it.

The class of the extension can be find somewhere in the source code of the applied plugin.

@JLLeitschuh
Copy link
Contributor

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants