Search code examples
javaintellij-ideagradlecompilation

Intellij - set default output path to gradle output


So, I created a new gradle project, choosing Java as "additional libraries and frameworks".

Gradle will compile to .\build\classes and maintain package structure,

but the "module compile output path" in project structure -> modules is set to .\out\production\classes.

That's really annoying and not something I want to remember having to change every time I create a new Java project.

Can I somehow change the default so it matches the gradle output path?


Solution

  • You can use the Gradle pluigin for INtelliJ

    In build.gradle:

    apply plugin: 'idea'
    
    idea{
        module{
            inheritOutputDirs = false
            outputDir = compileJava.destinationDir
            testOutputDir = compileTestJava.destinationDir
        }
    }
    

    Then when you run ...

    gradle idea
    

    ... it will generate complete IntelliJ project files for you.