buildship icon indicating copy to clipboard operation
buildship copied to clipboard

Add support extended test configuration such as integration test

Open gayanper opened this issue 3 years ago • 0 comments

When using plugin which introduce new configurations such as Integration Test which are extended from default test configurations, these custom configurations are not detected as test configurations.

Expected Behavior

custom configuration folders should be attached as test folders.

Context

project import

Solution

Using an init script segment as follows enables detected different sourcesets which are used for testing.

allprojects {
    afterEvaluate {project ->
        if(project.plugins.hasPlugin('java') || project.plugins.hasPlugin('java-library')) {
            project.apply plugin: 'eclipse'

            def configs = project.configurations.findAll { it.extendsFrom.any { it.name == 'testImplementation' }}.collect { it.name }
            def sourceSetNames = project.sourceSets.findAll { s -> configs.any { it == s.implementationConfigurationName } }.collect { it.name }

            project.eclipse.classpath.file.whenMerged { cp ->
                cp.entries.findAll { it.kind == 'src' }.each { entry ->
                    if (sourceSetNames.any {it == entry.entryAttributes['gradle_scope']}) {
                            entry.entryAttributes['test'] = 'true'
                    }                
                }
            }
        }
    }
}

gayanper avatar Aug 03 '22 11:08 gayanper