Jonas
Jonas

Reputation: 129093

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.

Upvotes: 18

Views: 32535

Answers (3)

mouhcine
mouhcine

Reputation: 61

In eclipse , right clik to you project => proporty => java build path =>in source check your folder enjoy

Upvotes: 3

MrJohnBBQ
MrJohnBBQ

Reputation: 313

Both previous answers are correct but I would also suggest adopting Gradle's convention (Maven's really) as it will save you a lot of time in the future just by being consistent.

Of course, you could always be consistent the other way around and add the custom srcDirs to every project, but it's easy enough to start every project with a:

$ mkdir -p src/{main,test}/{java,resources}

Food for thought. :)

Upvotes: 2

Peter Niederwieser
Peter Niederwieser

Reputation: 123996

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"]
        }
    }
}

Upvotes: 31

Related Questions