Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I set a folder as a Source Folder in Eclipse with Gradle?

I created a Java project and used Gradle to structure it with a source folder and a build folder with generated files.

Then I checked in the project using Git and checked it out on another computer. But on this second computer, I can't run this Java project since my src/ folder is not selected as a Source folder. How can I do this? should I have done anything different on the project setup using Gradle?

My build.gradle just contains these lines:

apply plugin: 'eclipse'
apply plugin: 'java'

When I try to run my computer on my second computer I get this error message:

Selection does not contain a main type

but it runs well on my first computer.

like image 596
Jonas Avatar asked Nov 11 '12 19:11

Jonas


People also ask

How do I mark a folder as source in eclipse?

Right-click the "java" directory and select Build Path | Use As Source Folder.

How do I set the gradle home directory in eclipse?

It is important to add the GRADLE_USER_HOME variable in Eclipse: Window->Preferences->Java->Build Path->Classpath Variable. Set it to the path of the ~/. gradle folder in your home directory (e.g. /home/<user_name>/. gradle/ (Unix) or C:\Users\<user_name>\.

What is the difference between source folder and folder in eclipse?

A source folder is marked by Eclipse as containing java sources. Then, when you compile your project Eclipse will look for your source code into all your source folders. You can make any folder become a source folder adding it to the java build path.


1 Answers

By default, the Java plugin assumes that production sources are located under src/main/java/. If they are located under src/, you'll have to let Gradle know:

sourceSets {
    main {
        java {
            srcDirs = ["src"]
        }
    }
}
like image 65
Peter Niederwieser Avatar answered Oct 14 '22 00:10

Peter Niederwieser