Gretty and Gradle 3.1

(Jim ) #1

I am having an issue when trying to add gretty to a build script. I get the following error:

“> Cannot change strategy of configuration ‘:overlays’ after it has been resolved.”

When not applying the gretty plugin, I am able to build the project without error. It seems to be a gretty issue, so I have added the same question on their message board as well. I am just hoping that there might be some help found here explaining the error a little bit so that I can better understand where the issue is. Thanks in advance.

Here is a pared down version of the build file that still creates the error message:

buildscript {
    repositories {
    dependencies {
        classpath 'org.akhikhl.gretty:gretty:1.4.0'

apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'org.akhikhl.gretty'

version = '2'
archivesBaseName = 'service'

compileJava {
    sourceCompatibility = 1.8
    targetCompatibility = 1.8

configurations {

repositories {

dependencies {
    overlays 'org.eclipse.jetty:jetty-distribution:9.3.9.v20160517@zip'

task overlayJetty(type: Copy) {
    def bundleRoot = 'build/bundle/project-' + project.version + '-bundle'
    def jettySrc = configurations.overlays.find {
    from zipTree(jettySrc)
    into bundleRoot
    includeEmptyDirs false
    eachFile {
        def path = it.relativePath.pathString
        path = path.replaceFirst('jetty-distribution-9.3.9.v20160517/', '')
        it.setRelativePath(RelativePath.parse(it.relativePath.isFile(), path))

task archiveBundle(type: Zip, dependsOn: overlayJetty) {
    from 'build/bundle'
    archiveName 'stream-service-' + project.version + ''

task bundle(dependsOn: archiveBundle)

(Benjamin Muschko) #2

Would you mind opening the issue directly on the GitHub page of the plugin? The maintainer of the plugin is committed to fix those issues and release a new version soon.

@Andrey_Hihlovskiy Could you please follow up on this issue?

(Andrey Hihlovskiy) #3

Will try to fix this issue in Gretty 1.4.1 (1 of February, 2017).

(Andrey Hihlovskiy) #4

Hey @JimHolladay,
I researched the problem - this is not a bug in Gretty, but rather the way Gradle handles the configurations. Particularly, the following code:

def jettySrc = configurations.overlays.find {

causes Gradle to resolve “overlays” configuration too early - at configuration phase.

I can suggest the following solution:

    def jettySrc = { zipTree(configurations.overlays.find {
    }) }
    from jettySrc

By introducing closure around “from” argument, you postpone configuration resolution until the “from” gets evaluated.

Please let me know, if it fixes the problem for you.

(Mark Vieira) #5

Better yet you can use FileCollection.filter() which will not trigger resolution and returns a lazily evaluated collection.

configurations.overlays.filter { it.absolutePath.contains('jetty') }

Note that this returns a collection rather than a single item like Groovy’s find(), but passing the result into something like CopySpec.from() should result in identical behavior.