How to exclude duplicated classes from “out” directory from compilation, when using gradle and tools like lombok, google protobuf and swagger

已回答

Hi. My project has many modules and we're using gradle with few code generators. Example configuration:

sourceSets {
...
    swagger {
        compileClasspath = configurations.swaggerCompile
        java {
            srcDir file("${project.buildDir.path}/build/generated/source/swagger/")
        }
    }
    main {
        java {
            srcDirs 'build/generated/source/proto/main/...'
        }
    }
    test {
        java {
            srcDirs 'build/generated/source/proto/main/...'
        }
    }
}

ext {
    generatedSourcesDir = 'build/generated/source'
}

protobuf {
    ...
    generatedFilesBaseDir = "${buildDir}/generated-src/..."
}

Project doesn't compile with Intellij, because its generating classes both in specified directories and in /out/ directory generated by Intellij.

Same duplicated classes are for example generated in:

\out\production\classes\generated\ - Intellij \build\generated-src..\ - Gradle

It gives me hundreds of error messages like: Error:(30, 14) java: duplicate class: com.xxx.xxx.xxx.YourClass I've tried everything I could find here and on Intellij forums. Nothing worked for me.

I even tried to exclude "out" directory in File > Settings > Build, Execution, Deployment > Compiler > Excludes but it doesn't work either.

The only way is to build project, manually delete all "out" dirs and then disable annotation processors. But it's not the best way to make it working.

0
Enable Settings (Preferences on macOS) | Build, Execution, Deployment | Build Tools | Gradle | Runner | Delegate IDE build/run actions to gradle option - this should fix build errors.
 
Another option to try is to disable Create Separate modules per source set in Gradle settings.
3
Avatar
Permanently deleted user

Thank you, but it's making even more problems. When I try to run my SpringBootApp I get: CreateProcess error=206, The filename or extension is too long

There are many solutions like this, but it's generating more problems.

I can't launch main method of springboot application (i need to run in debug mode), directly from Intellij, because it's delegated to Gradle. Anyway it starts new issues with classpath to long, packages, which intellij doesn't recognize etc. I just need Intellij to stop generating this files.

0

>How to exclude duplicated classes from “out” directory from compilation

You get duplicated classes because of using Gradle build results and IDE build results. In case when using either only IDE build or only Gradle build there should be no such issue. The preferred way is to use delegate to Gradle mode, since this way you will always get the same behaviour as when you build and run it by Gradle.

>When I try to run my SpringBootApp I get: CreateProcess error=206, The filename or extension is too long

We must fix the this classpath issue in delegate mode: https://youtrack.jetbrains.com/issue/IDEA-178417 I've forwarded your report to the responsible developer. Please feel free to follow YouTrack issue for updates. I hope it will be fixed in nearest IDE updates.

0

The https://youtrack.jetbrains.com/issue/IDEA-178417 has been fixed and will be included into next 2019.1 version update.

-1

请先登录再写评论。