Gradle Project Resources Not Added to Classpath

1.8k views Asked by At

I've been tasked with write some base classes for automated integration tests for an existing project, and I've run into a snag with project dependencies.

The (abstracted) project layout is this:

project /
    MainProject
    Plugins /
        ...
    ConfigurationProject
    IntegrationTestProject

IntegrationTestProject has a dependency upon ConfigurationProject, the latter having the following layout:

ConfigurationProject/
    PluginConfigs/
        <plugin configuration files>
    <main configuration files>

Notably, the main configuration files reside in the root of the project. In an attempt to add them to my classpath, my primary build.gradle has the following:

project('ConfigurationProject') {
    description = 'Configuration'
    sourceSets.main.resources.srcDir projectDir
}

This seems to look okay, as eclipse shows all files in root as being part of the project resources, and assembling packages everything up as expected.

However, when I actually go to run the integration tests, the ConfigurationProject resources do not seem to be in the classpath, as it fails to pull config information, further confirmed by the lack of ConfigurationProject present in outputs from this snippet:

public void classpathScanner() {
    ClassLoader c=getClass().getClassLoader();
    System.out.println("c="+c);
    URLClassLoader u=(URLClassLoader)c;
    URL[] urls=u.getURLs();
    for (URL i : urls) {
        System.out.println("url: "+i);
    }
}

The ConfigurationProject is included in IntegrationTestProject using the IntegrationTestProjects gradle.build

dependencies {
    compile project(':ConfigurationProject')
}

I have only observed this problem when adding the project root as a resource, addng subfolders of a project to sourceSets seems fine (and is used elsewhere in this project). Moving the configuration files to a subfolder is an option I have considered, and will enact if I find no other solution, but I wanted to see if there were options that did not involve this course of action.

1

There are 1 answers

0
Brandon McKenzie On BEST ANSWER

The answer to this is essentially "don't make project root a resource folder, Gradle hates that, and even if it didn't, it's bad form anyway" I fixed this by placing the configuration files to a more sensible resource path.