How to add test resource resources in Gradle / IntelliJ

Using IntelliJ 14 and the idea plugin in Gradle 2.2 to create IntelliJ projects. I can add a new root test source for integration tests as follows:

idea {
    module {
        testSourceDirs += file('src/integrationTest/java')
    }
}

However, I did not find a way to add the corresponding Resource Root tag located in 'src / integrationTest / resources'. Any ideas how to do this? Thank you very much in advance.

-Daniel

+4
source share
2 answers

That should work :)

idea { 
    module.iml.withXml {
        def node = it.asNode()
        def content = node.component.find { it.'@name' == 'NewModuleRootManager' }.content[0]
        content.sourceFolder.each { sourceFolder ->
            if(sourceFolder.@url?.endsWith('/resources')) {
                sourceFolder.attributes().with {
                    boolean isTestSource = (remove('isTestSource') == 'true')
                    put('type', isTestSource ? 'java-test-resource' : 'java-resource')
                }
            }
        }
    }
}
+1
source

, Cucumber. src/cucumber/java src/cucumber/groovy, src/cucumber/resources, IntelliJ cucumber . , :

idea {
    // Workaround to make sure the cucumber resources folder is
    // marked as "Test Resource Root" in IntelliJ. Otherwise the
    // IntelliJ cucumber integration gets confused wrt looking
    // up step definitions, highlighting, etc.
    module {
        testSourceDirs += file('src/cucumber/resources')
    }
    module.iml.withXml {
        def node = it.asNode()
        def content = node.component.find { it.'@name' == 'NewModuleRootManager' }.content[0]

        def cucumberSources = content.sourceFolder.findAll { it.@url?.contains('/src/cucumber/resources') }
        cucumberSources.each {
            it.@type = 'java-test-resource'
        }
    }
}
0

Source: https://habr.com/ru/post/1569817/


All Articles