This message was deleted.
# community-support
s
This message was deleted.
m
you shouldn't do that, as this is unsafe and will eventually break (with project isolation)
agreed that it is not ideal as this requires some ceremony...
long story short: if you need the output of a task from another project, then it should be declared as a proper "outgoing artifact".
c
If thats the way to go, I will have a look at it again. Seams overly complicated for somethings as simple as sharing project outputs.
m
It's not super complicated once you are used to it 🙂 Mindset shift.
there could be some conventional way to refer to another project task's as an input, for example, by having some implicit outgoing configuration for every task. That would work, but it would still be much more fragile than the recommended way. For example, it would break as soon as you rename the task, or, as soon as you want more tasks to contribute to that output.
c
Still got a lot of question marks. At the producer side i have:
Copy code
task buildClient(type: Exec) {
    outputs.dir file('build')
    ....
}

configurations {
    webResource {
        canBeConsumed = true
        canBeResolved = false
    }
}

artifacts {
    webResource(buildClient.outputs.files.singleFile)
//   Documentation suggests this is needed but adding it results in a compile error missing function
//   {
//        buildBy(buildClient)
//   }
}
Consumer:
Copy code
configurations {
    webResources {
        canBeConsumed = false
        canBeResolved = true
    }
}

dependencies {
    // If i get this correct this means, put the webResource from consumer-proj into the webResources configuration
    webResources(project(path: ':consumer-proj', configuration: 'webResource'))
}

sourceSets {
    main {
        resources  {
            srcDir(configurations.webResources.resolve())
        }
    }
}
Runs but the resources are not there and
buildClient
is not run
m
so apparently using a configuration as
srcDir
triggers a
StackOverflowError
so I managed to make this work by using an intermediate task. On the producer:
Copy code
plugins {
   id 'base'
}

configurations {
    webResources {
        canBeConsumed = true
        canBeResolved = false
    }
}

def generateSources = tasks.register("generateSources", GenerateSources) {
    outputDirectory = layout.buildDirectory.dir("generated-java")
}

configurations.webResources.outgoing.artifact(generateSources)

abstract class GenerateSources extends DefaultTask {
    @OutputDirectory
    abstract DirectoryProperty getOutputDirectory()

    @TaskAction
    void generate() {
       new File(outputDirectory.get().asFile, "Foo.java").text = "public class Foo {}"
    }
}
then in the consumer:
Copy code
plugins {
    id 'java'
}

configurations {
    webResources {
        canBeConsumed = false
        canBeResolved = true
    }
}

dependencies {
    webResources project(path:':producer', configuration: 'webResources')
}

def copy = tasks.register("copy", Copy) {
    from configurations.webResources
    into layout.buildDirectory.dir("sources-java")
}

sourceSets {
   main {
       java.srcDir(copy)
   }
}
I wished we could use
sourceSets.main.java.srcDir(configurations.webResources
directly, but this triggers the
StackOverflow
c
Yeah, ran into the StackOverflow as well.
Seeing this, it feels a lot more complicated and less elegant than the initial sollution
v
But it is not unsafe and unsupported :-D Btw. the compile error was due to
buildBy
vs.
builtBy
.
c
@Vampire Agreed, I'm trying to fix it in the correct way. And indeed fixing the typo resolves the compile issue.
👌 1
Got it working but still not sure if I like the solution. On the producer side I now have:
Copy code
configurations {
    webResources {
        canBeConsumed = true
        canBeResolved = false
    }
}

artifacts {
    webResources(buildClient.outputs.files.singleFile) {
        builtBy(buildClient)
   }
}
Adding all the outputs to the webResources artifact still seams clunky and only works because I know there is only one directory. This is probably because the Exec task that is used to generate the resources has no nice OutputDir type
DirectoryProperty
. But overall this is not that bad. Consumer:
Copy code
configurations {
    webResources {
        canBeConsumed = false
        canBeResolved = true
    }
}

dependencies {
    webResources project(path: ':producer', configuration: 'webResources')
}

def copy = tasks.register("copy", Copy) {
    from configurations.webResources
    into layout.buildDirectory.dir("webresources")
}

sourceSets {
    main {
        resources  {
            srcDir(copy)
            //srcDir(tasks.getByPath(":producer:buildClient").outputs)
        }
    }
}
Sill don't really like the extra copy task. Upside I suppose is that the copy task allows me to place the artifacts in a sub dir if needed. Should I submit a bug report about the stackoverflow if you do
srcDir(configurations.webResources)
?
v
Sounds to me like it should either be fixed or at least have some sanity check and fail in a more meaningful way.