Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I replace the default source folders for gradle?

I am new to Gradle and I have a source code location different than what Gradle expects.

Gradle expects to find the production source code under src/main/java and your test source code under src/main/resources. How do I configure Gradle to a different source code?

like image 757
anirus Avatar asked Feb 14 '14 04:02

anirus


People also ask

How do I change directory in Gradle?

On android studio just go to File > Settings > Build Execution, Deployment > Gradle > Service directory path choose directory what you want.

How do I change the Gradle path in Windows 10?

In File Explorer right-click on the This PC (or Computer ) icon, then click Properties -> Advanced System Settings -> Environmental Variables . Under System Variables select Path , then click Edit . Add an entry for C:\Gradle\gradle-7.5.1\bin . Click OK to save.

What is source set in Gradle?

An AndroidSourceSet represents a logical group of Java, aidl and RenderScript sources as well as Android and non-Android (Java-style) resources.

How do I find the .Gradle folder?

The default location for the files for a Windows user is under the Users directory on the C: drive. So a user called John Doe would have a folder at C:\Users\John Doe. This user directory is where the Windows . gradle folder is located.


1 Answers

You have to add few lines to build.gradle:

To replace the default source folders, you will want to use srcDirs instead, which takes an array of the path.

    sourceSets {
        main.java.srcDirs = ['src/java']
        main.resources.srcDirs = ['src/resources']
    }

Another way of doing it is:

    sourceSets {
        main {
            java {
                srcDir 'src/java'
            }
            resources {
                srcDir 'src/resources'
            }
        }
    }

The same thing is applicable to test folder too.

like image 50
anirus Avatar answered Oct 26 '22 12:10

anirus