0

I haven't done anything with Gradle for a while, so it appears I've forgotten how configuration resolution works.

I'm trying to use the gretty plugin (instead of core, deprecated jetty), but I cannot seem to create a custom configuration.

I've boiled it down to a very short, simple script (using Gradle 3.4):

buildscript {
    repositories {
        maven {
            url 'https://plugins.gradle.org/m2/'
        }
    }
    dependencies {
        classpath 'org.akhikhl.gretty:gretty:1.4.0'
    }
}

plugins {
    id 'org.akhikhl.gretty' version '1.4.0'
}

configurations {
    fooTest
}

configurations.fooTest.each {
    println it.toString()
}

It seems to not like me iterating over the fooTest configuration.

Assuming I need to know the dependencies for that configuration (I stripped that part from the code above)

What am I doing wrong here?

The script above gives me this:

org.gradle.api.InvalidUserDataException: Cannot change strategy of configuration ':fooTest' after it has been resolved.
Fendec
  • 367
  • 1
  • 5
  • 23
Depressio
  • 1,329
  • 2
  • 20
  • 39
  • What do you expect to see by executing `println it.toString() `? – Andrii Abramov Mar 07 '17 at 18:34
  • I'm using `fooTest` in dependency configurations (which I neglected to put since I get the error regardless). I don't necessarily want to print the dependencies, but I do want to unzip some zip dependencies which is why I need to iterate over them. I just wanted to narrow the question down as much as I can. – Depressio Mar 07 '17 at 19:59

1 Answers1

0

The key point here was that I needed an unresolved configuration to loop over. Admittedly this information was neglected in the initial description as I didn't know it was critical information. We needed to loop over the files in the dependency and copy/unzip them into certain locations.

However, we cannot do that with a resolved configuration. That said, we can copy the configuration into a unresolved one, and loop over that instead:

configurations.fooTest.copy().each {
    println it.toString()
}

This will successfully print out the files involved in the dependency (or unzip them, as my case needs).

Depressio
  • 1,329
  • 2
  • 20
  • 39