How to use default output directory for all source folders in eclipse

How can I make the .classpath file generated by the “gradle eclipse” command use the default output directory for all source folders?

With this build file, and a single “src/main/java” folder:

buildDir = "build/gradle"
apply plugin: 'java'
apply plugin: 'eclipse'
eclipse {
  classpath {
    defaultOutputDir = file('build/eclipse')
  }
}

Using 4.3.1, “gradle eclipse” produces the following in the “.classpath” file:

<classpathentry path="build/eclipse" kind="output"/>
<classpathentry kind="src" path="src/main/java"/>

However after upgrading to 4.6 it produces the following:

<classpathentry kind="output" path="build/eclipse"/>
<classpathentry output="bin/main" kind="src" path="src/main/java">
    <attributes>
        <attribute name="gradle_scope" value="main"/>
        <attribute name="gradle_used_by_scope" value="main,test"/>
    </attributes>
</classpathentry>

How can I tell gradle to use the default output directory for all source folders, and not add a specific output dir? Alternatively, separate output folders would be ok, as long as they are created under the default output dir.

I just need:

  • All gradle build files to be under “build/gradle”
  • All eclipse build files to be under “build/eclipse”

Thanks

1 Like

I had issues with this as well. Following is what helped me.
In the rootproject I do this:

subprocjects {
  eclipse {
	classpath {
		file {
        	whenMerged { 
    	    	// use default Output for all source-folders. see also defaultOutputDir per project
	        	entries.each { source ->
					if (source.kind == 'src' && !source.path.startsWith('/')) { // only Source-folders in the project starting with '/' are project-references
						source.output = null
        			}
				}
    	    }
	    }
	}
}
}

but you propably could do this in the project itself if you don’t use subprojects.

and on each project I set the desired output like this

eclipse {
	classpath {
		defaultOutputDir = file('bin')
	}
}

hope this helps.

1 Like