6

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?

User1291
  • 7,664
  • 8
  • 51
  • 108

1 Answers1

15

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.

glytching
  • 44,936
  • 9
  • 114
  • 120
  • THANK you! This is a lot more convenient. I have no idea why this is not done automatically on project creation... – User1291 Sep 26 '17 at 08:11
  • @User1291 it's not done automatically for a good reason, see https://youtrack.jetbrains.com/issue/IDEA-175172 for the explanation. – CrazyCoder Sep 26 '17 at 08:34
  • @CrazyCoder Then what's the point in having gradle at all if you're going to bypass it anyway? – User1291 Sep 26 '17 at 08:54
  • @User1291 so that you don't have to configure all the modules and dependencies manually. If you prefer IDE to use Gradle for everything, there is an option to delegate builds to Gradle. – CrazyCoder Sep 26 '17 at 14:04
  • @CrazyCoder Is that actually so? I haven't tried, so I don't know, but if I use Gradle to define dependencies and then DON'T build with Gradle, will the IDE actually benefit from Gradle. Another issue I'm having is that the bytecode viewer will look in the wrong place for the .class files. Will delegating builds to Gradle fix that or would I still have to run ``gradle idea``? – User1291 Sep 26 '17 at 14:08
  • 5
    @User1291 `gradle idea` is obsolete, see http://stackoverflow.com/a/42518961/104891. User benefits from Gradle since he doesn't need to configure anything manually. Whether the build is performed by Gradle or by IntelliJ IDEA is not relevant in most cases and IntelliJ IDEA incremental build is usually faster. If you want Gradle to do everything instead of IntelliJ IDEA, use the "delegate" option. – CrazyCoder Sep 26 '17 at 14:10
  • 1
    @CrazyCoder Thank you. I'll keep glitch's answer because it answers the question the way I have asked it, but I definitely appreciate your comments. – User1291 Sep 26 '17 at 14:36
  • 1
    Is there an option to set specific outputDir for each module? For example I want my modules to compile to: idea { module { inheritOutputDirs = false outputDir = compileJava.destinationDir + ${module.name} testOutputDir = compileTestJava.destinationDir + ${module.name} } } – blackuprise Aug 28 '19 at 10:23