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

Extensions Arrays are imutable #712

Closed
StefMa opened this issue Feb 8, 2018 · 3 comments
Closed

Extensions Arrays are imutable #712

StefMa opened this issue Feb 8, 2018 · 3 comments

Comments

@StefMa
Copy link
Contributor

StefMa commented Feb 8, 2018

In a project I want to use this plugin.
Unfortunately I can't set/change the licences from their extension in a expected way.

This is the extension from the plugin.
As you see. licenses have a default value:
String[] licences = ['Apache-2.0']

Expected Behavior

In the Groovy DLS I use the following code:

publish {
//... Other code - ignore me
    licences = ["MIT"]
}

With that code the license array will be overwritten and it works.

I expect that I can set the licenses in kotlin similar to groovy:

publish {
//... Other code - ignore me
    licences = arrayOf("MIT")
}

Current Behavior

If I use the same code in the Kotlin-DSL I get the error:
bildschirmfoto 2018-02-08 um 15 33 22

I can't workaround it somehow. First I thought I can use

licences.toMutableList().add("MIT")

but since the toMutableList() will return a new list I have to set the new list (which I have to convert to array first of course) to the licenses field of the extension. But since it is immutable I can't set it 😞

Context

N/A

Steps to Reproduce (for bugs)

You could create a new project and add the following code:
settings.gradle

pluginManagement {
    repositories {
        gradlePluginPortal()
    }
    resolutionStrategy {
        eachPlugin {
            if (requested.id.id == "com.novoda.bintray-release") {
                useModule("com.novoda:bintray-release:${requested.version}")
            }
        }
    }
}

build.gradle.kts

plugins {
    id("java-library")
    id("com.novoda.bintray-release") version "0.8.0"
}

publish {
    userOrg = "anyOrg"
    groupId = "aGroupdId"
    artifactId = "artifactId"
    uploadName = "name"
    version = "AVersion"
    description = "A descritpion"
    website = "https://github.com/gradle/kotlin-dsl"
    licences = arrayOf("MIT")
}

Your Environment

  • Build scan URL:
    I think a build scan make no sense here
@mkobit
Copy link
Contributor

mkobit commented Feb 8, 2018

Current workaround is to call the setter that uses varargs -> setLicenses("MIT")

@StefMa
Copy link
Contributor Author

StefMa commented Feb 9, 2018

@mkobit hmm, I don't know what do you mean.
According to my build.script there is no setLicenses:
bildschirmfoto 2018-02-09 um 09 03 09

Update:

Ok, it's just appear:
bildschirmfoto 2018-02-09 um 09 05 38

@eskatos
Copy link
Member

eskatos commented Apr 3, 2018

That's causes by Groovy generating a property setter that takes a vararg for an array.
Plugin types should prefer collections.

Also note that #380 could help here.

Closing as answered

@eskatos eskatos closed this as completed Apr 3, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants