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

Using multi-catch results in compilation failure #28

Closed
davidmc24 opened this issue Dec 27, 2013 · 6 comments
Closed

Using multi-catch results in compilation failure #28

davidmc24 opened this issue Dec 27, 2013 · 6 comments

Comments

@davidmc24
Copy link

If you have classes that use a Groovy multi-catch block (available since Groovy 2.0), these classes will fail to compile in CodeNarc. The failure looks sort of like this when building with Gradle:

:myapp:codenarcMain
Compilation failed for [SourceFile[/Users/myuser/git-repos/myapp/src/main/groovy/myapp/MyClassName.groovy]].

It does not appear to cause any issues to appear in the CodeNarc report. I'm unsure of whether rules are actually being run against these classes or not.

It appears that this is caused by using an old version of Groovy (1.7.5) for the compilation, resulting in an "unexpected token" error since it doesn't know about the multi-catch syntax that was introduced in later versions of Groovy.

http://groovy.codehaus.org/JN3035-Exceptions

@chrismair
Copy link
Contributor

Since CodeNarc uses the Groovy compiler, perhaps using a more compatible version of Groovy would help. Have you tried running CodeNarc against this source code with Groovy 2.x?

@davidmc24
Copy link
Author

The project where I first saw this issue was definitely using Groovy 2.x, and calling Codenarc via Gradle. I was basing my statements of 1.7.5 being used on reproducing the behavior within CodeNarc's test suite, but that may not be an accurate test for this issue. If CodeNarc uses the provided Groovy's compiler, perhaps the problem is that the Gradle CodeNarc plugin is using a different version of Groovy than the one specified?

@chrismair
Copy link
Contributor

The Gradle CodeNarc plugin (http://www.gradle.org/docs/current/userguide/codenarc_plugin.html) apparently allows specifying a dependency configuration for the CodeNarc libraries (version) to use, but I have not tried that myself.

@davidmc24
Copy link
Author

Assuming you mean the toolVersion property, I tried that. Same behavior (for this) between the default version and 0.20.

UPDATE: upon re-reading, I now see a mention of the "codenarc" dependency configuration. I wish there was an example of use. I'll try to figure it out.

@davidmc24
Copy link
Author

I've tried using the "codenarc" dependency configuration, and it doesn't look like it helps either. However, I think I may have found the real root-cause of the problem. Gradle is calling the CodeNarc Ant task using an IsolatedAntBuilder, but doesn't appear to be specifying the Groovy to use (and thus defaulting to Gradle's Groovy). For Gradle 1.10, that's Groovy 1.8.6. I'll close this issue after opening a follow-up issue with the Gradle project.

https://github.com/gradle/gradle/blob/master/subprojects/code-quality/src/main/groovy/org/gradle/api/plugins/quality/CodeNarc.groovy#L127
https://github.com/gradle/gradle/blob/master/subprojects/core/src/main/groovy/org/gradle/api/internal/project/IsolatedAntBuilder.java

@davidmc24
Copy link
Author

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