Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Groovlets causing "The declared package "" does not match the expected package" warning #492

Closed
gregg-saffell opened this issue Feb 20, 2018 · 9 comments
Assignees
Milestone

Comments

@gregg-saffell
Copy link

I think the fix for "No warning for source unit with missing package statement #473" is causing problems for projects with groovlets. Very recently, Eclipse Oxygen 2 with v 3.0.0 of the plugin started showing warnings like the following for all of the .groovy files I have under webApplication/WEB-INF: "The declared package "" does not match the expected package "webApplication.WEB-INF.toolDelete" Because these files are "groovlets," they are not supposed to have a package name. They are scripts that get compiled by groovy.servlet.GroovyServlet.

I looked for a way to tell the plugin to treat any .groovy file under webApplication/WEB-INF as scripts but I could not figure out what to add to the "Groovy Script Folder" section of the Groovy Preferences panel.

Thanks in advance!

@eric-milles
Copy link
Member

Could you supply a small sample project? I'm not familiar with groovlets. I'd like to understand if WEB-INF is being seen as within a source folder or not.

@eric-milles eric-milles added this to the v3.0.0 milestone Feb 20, 2018
@gregg-saffell
Copy link
Author

sample_web_proj.zip

The attached zip is of my eclipse project with everything deleted except the overall project structure and one groovlet. In the original, there are .jsp files right along-side the groovlet files.

Groovlets are described here: http://docs.groovy-lang.org/latest/html/documentation/servlet-userguide.html . The idea is you create a servlet mapping between groovy.servlet.GroovyServlet and your .groovy scripts in your web.xml. At runtime, when someone hits a url that maps to a .groovy script, GroovyServlet compiles it (much like a JSP is compiled the first time it is referenced).

I should add, this is actually an error, not a warning. I am able to work around it since my build is actually done via Ant so having this build error in eclipse isn't holding me up.

@eric-milles
Copy link
Member

From what I can tell from your sample project, you don't actually need to have the source and output folders defined in the .classpath file. If you leverage GroovyServlet to discover and compile your groovlets, the Eclipse Java builder is not offering anything. When I removed these lines from .classpath, the errors were not seen because compilation was stopped:

<classpath>
	<!--classpathentry kind="src" path=""/>
	<classpathentry kind="output" path=""/-->
	<classpathentry kind="con" path="GROOVY_SUPPORT"/>
	<classpathentry kind="con" path="GROOVY_DSL_SUPPORT"/>
	<!--classpathentry kind="lib" path="R:/third_party/sun/J2EE/EJB/v7.0/lib/j2ee.jar"/-->
	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
</classpath>

@gregg-saffell
Copy link
Author

In the real project, there are java and groovy source code files that do get compiled but they are not under webApplication/WEB-INF. They are in packages that start at the root of the project's source path (e.g., com.ils.ediag...). The files under WEB-INF are xml, groovy, and jsp files.

What is probably most important to keep in mind is this project has existed for years with groovlets and did not have this problem last week.

@eric-milles
Copy link
Member

Sure, but the META-INF and WEB-INF stuff is not meant to be compiled, correct? You are specifying your entire project as a source container, therefore any Java or Groovy sources contained within are compiled. If you don't want your groovlet sources to get compiled, they should be moved off the build path or marked as Groovy scripts.

To indicate that everything in webApplication/WEB-INF is a script, you need to check the box "Enable project specific settings" on the Groovy Compiler page.

@gregg-saffell
Copy link
Author

I tried the "Enable project specific settings" on the Groovy Compiler page specifying this as a groovy script filter: "webApplication/WEB-INF/**/*.groovy" but that has no effect. If I use that same criteria as an eclipse source exclusion filter, the errors go away.

Do you know what is wrong with the groovy script filter: "webApplication/WEB-INF/**/*.groovy"?

I guess I'm fine with having to add this, this is an old project that was set up before I joined the company (although I did add Groovy to it). It's just that this was not a problem last week. The only thing that changed was an update to th plugin.

@eric-milles
Copy link
Member

Nothing wrong with the filter. I am trying it out now to be sure everything holds. The script is still being processed as a compilation unit to a point and the package check is still being performed. There was a check for scripts as part of the package name check. I'm checking on that now.

eric-milles added a commit that referenced this issue Feb 21, 2018
- improves handling for project root as output location
@eric-milles
Copy link
Member

Could you update to the latest and test again with the script filter enabled?

@gregg-saffell
Copy link
Author

The script filter is now solving the problem. Thanks!

@eric-milles eric-milles self-assigned this Apr 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants