Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Problem with search path for type-checking extensions #1397

Closed
chrylis opened this issue Sep 27, 2022 · 5 comments
Closed

Problem with search path for type-checking extensions #1397

chrylis opened this issue Sep 27, 2022 · 5 comments
Assignees
Labels
Milestone

Comments

@chrylis
Copy link

chrylis commented Sep 27, 2022

I'm actively working on a type-checking extension, which is in the src/main/resources of my project. My class has @CompileStatic(extensions = 'my/extension.groovy'). This works correctly in the Maven CLI build and in Eclipse if I run Maven through at least process-resources, but using a Eclipse clean causes

Groovy:Static type checking extension 'my/extension.groovy' was not found on the classpath.

The problem appears to be a sequencing problem regarding resource access.

@eric-milles
Copy link
Member

Can you share at least the structure of your project? Does eclipse recognize src/main/resources as a source folder? To get UI support, it needs to be a source folder and then you probably want a groovy script filter on it to prevent compilation. Let me know if you need help understanding how to set up those two things.

@chrylis
Copy link
Author

chrylis commented Sep 29, 2022

It does recognize the folder as a source folder. I am not sure about the "Groovy script filter"; I was unaware of the concept until now.

@eric-milles
Copy link
Member

eric-milles commented Sep 30, 2022

Eclipse does not have the distinction of source and resource directories like Maven does. To have resources available through classpath, they must be source folders. Any groovy source unit in a source folder will be compiled, unless it is matched by a script filter. The m2e project configurator should probably apply a groovy script filter for any maven resource directory that is manifested as an eclipse source folder.

Update: the script filter sits between full exclusion and full inclusion. As-is a source folder includes all files. An exclusion can be set so eclipse ignores files matching a pattern; this prevents compilation but also prevents copying to output folder. Script filter can prevent compilation while still supporting copying of scripts to the output folder (for classpath inclusion).

@eric-milles
Copy link
Member

I've used gradle to write script filters (see below). I think maven-eclipse-plugin can do a similar thing, if you are interested in automating configuration.

        apply plugin: 'eclipse'
        project.tasks.eclipse.doLast {
            if (!file("${project.projectDir}/.classpath").exists()) return

            file("${project.projectDir}/.settings/org.eclipse.jdt.groovy.core.prefs").with { prefs ->
                if (!prefs.exists()) {
                    append('''\
                        eclipse.preferences.version=1
                        groovy.compiler.level=40
                        groovy.script.filters=**/*.gradle,n,**/script*.groovy,y,**/*resources/**/*.groovy,y,**/benchmarks/**/*.groovy,y
                        org.codehaus.groovy.eclipse.preferences.compiler.project=true
                        '''.stripIndent()
                    )
                }
            }

@eric-milles
Copy link
Member

I could look into changing the m2e project configurator to add script filters for resource directories. I'm not sure if m2e reapplies the configurator when you update a Maven project or if you would need to re-import the project. Thoughts?

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants