Impossible to remove main source set when using eclipse plugin?


(thirsch81) #1

I would like to create source directories for custom source sets and also use the eclipse plugin. I also would like to not have a ‘main’ source set in my project.

The example can be found here https://github.com/thokari/gradle-workshop/blob/master/examples/07-multiple-artifacts/build.gradle

Now it would be easy if I could just use

sourceSets { remove main }

, but then the eclipse plugin stops working: >* What went wrong: >Could not determine the dependencies of task ‘:eclipseClasspath’. >Could not find property ‘main’ on SourceSet container.

I guess it is because of lines 139, 142 in https://github.com/gradle/gradle/blob/351e5d7988d451bf551410b8e59797c98c3152ff/subprojects/ide/src/main/groovy/org/gradle/plugins/ide/eclipse/EclipsePlugin.groovy

I am wondering why this convention is hard coded in this way.

Is there a drawback in always adding all declared java source sets to the classpath? When working with multiple source sets, usually the first thing I do is

eclipse {
    classpath.plusConfigurations += configurations.newConfiguration
}

I feel like this should be default… Could the problem be with this, that you could actually create a project which shows no errors in Eclipse but cannot compile with Gradle? I.e. if you added all configurations to the eclipse classpath, without declaring possible source set dependencies?


(Radim Kubacki) #2

Re main sourceSet: you are right that eclipse (and idea) plugin has some hard-coded depencencies on java plugin. Generally we want to make it better configurable. This should cover cases when java-base plugin is used without java plugin (http://issues.gradle.org/browse/GRADLE-2251). I am not sure when this will happen but if you really need it you can consider submitting a patch.

As for the mapping between configurations and Eclipse classpath: Eclipse project has much simpler model for its classpath and it means that the generated classpath is an approximation and there is no universal solutions (https://bugs.eclipse.org/bugs/show_bug.cgi?id=105372 is related to this topic). The default works well for project without special customization and it feels easier and safer to let people add than to ask them to filter inappropriately added content.