IntelliJ + groovy DSL: How to exclude files from compilation using the groovy plugin?

I am working on a Java web project that uses Liquibase groovy DSL to manage database changes. For the sake of this topic, there can be any other third-party library that uses *.groovy files as sources. The project is built using gradle. In one of my modules ( dao-base ) in the src/main/resources folder I have groovy files ( changelog01.groovy, master_changelog.groovy , etc.). these files must be downloaded by Liquibase at runtime.

Now, when I try to make a project in IntelliJ, it gives the following error message:

Groovyc: Unable to compile groovy files: The groovy library is defined for the dao-base module.

I realized that the groovy plugin detects *.groovy files, tries to compile them, and unsurprisingly fails. These are groovy DSL files that should only be downloaded by a third-party Liquibase analyzer, and I donโ€™t need the IntelliJ groovy plugin to try to compile them.

I managed to find 2 partial solutions: 1. disable the groovy plugin in intellij. The problem with this solution is that the gradle plugin is dependent on the groovy plugin and therefore automatically shuts down when the groovy plugin is disabled. I need a gradle plugin. 2. excluding the src/main/resources folder in the project settings โ†’ modules โ†’ dao-base (my module) โ†’ sources tab. The problem with this solution is that when I create a project and deploy it to tomcat, there are no files from the resource folder, and since the files are required at runtime, I get a file exception not found when loading the war.

I was hoping that someone could come up with a better solution to this problem.

+6
source share
3 answers

Try removing the suffix of the groovy file from the compiler resource list:

Settings โ†’ Compiler

IntelliJ IDEA Compiler Settings

+14
source

Are you generating an IntelliJ project using the Gradle Idea Plugin ? If so, you can add these groovy files to the compiler resource list in IntelliJ via gradle by adding this to build.gradle:

 idea { project { // customize the .ipr file generation. ipr { withXml { xmlProvider -> def project = xmlProvider.asNode() // Add appropriate groovy files to the compiler resources. These files will not be compiled by the groovy compiler but will be copied to the classes directory during compilation. def compilerSettings = project.component.find { it.@name == 'CompilerConfiguration' } compilerSettings.wildcardResourcePatterns*.appendNode('entry', [name: '*/changelog*.groovy']) compilerSettings.wildcardResourcePatterns*.appendNode('entry', [name: '*/master_changelog.groovy']) } } } } 

This is good because you will not have to forget to do it manually when creating a project from gradle.

0
source

I faced the same problem. I disabled the groovy plugin from the settings after this successful compilation, and also completed my project.

-1
source

Source: https://habr.com/ru/post/949752/


All Articles