El Mac
El Mac

Reputation: 3419

Gradle on IntelliJ Folder Structure

I need help including Gradle in an already existing project.

My main problem is that the project structure is not the "default" Gradle structure. I also have three projects in my Idea Project, which makes it more difficult.

My projects:

This is my folder structure:

So I get nice URL Style packets for my classes. (i.e.: com.elmac.client.Main)

My concrete question

Where do I have to put which gradle files, and what do I have to write in the files, in order to create two .JAR files (Client and Server depend from shared --> Shared does not need a jar file).

I got really confused with the dozens of tutorials, each containing similar structures that are not similar to mine. And I havent figured out how to include my projects (I dont even know where to put which file on this project structure!)

Upvotes: 1

Views: 824

Answers (1)

MartinTeeVarga
MartinTeeVarga

Reputation: 10898

I do not understand your reasoning "So I get nice URL Style packets for my classes." You would get that even if you split them into the subprojects and use a more standard directory structure. You can then have both client and server subproject depend on the shared subproject (either as jars or directly as with the project dependency).

However to answer your question, you can start by defining different source sets in the build.gradle:

sourceSets {
    client {
        java {
            srcDirs = ["$projectDir/src"]
            include '**/client/**'
        }
...
}

These will then be compiled into separate directories in the build dir. Then you can build your jars from these source sets:

task clientJar(type: Jar) {
    from sourceSets.client.output
}

You might run into problems with IntelliJ because it can have only one output directory for main and one for tests in each module, so you can't use IntelliJ compile & run anymore (e.g. when running single unit tests), you will have to run everything using gradle tasks.

Upvotes: 1

Related Questions