[GRADLE-1190] Gradle groovy plugin and joint compilation Created: 27/Oct/10  Updated: 10/Feb/17  Resolved: 10/Feb/17

Status: Resolved
Project: Gradle
Affects Version/s: 0.9
Fix Version/s: None

Type: Bug
Reporter: Sargis Harutyunyan Assignee: Unassigned
Resolution: Won't Fix Votes: 3


 Description   

Hi I have following interface in folder: src/main/java/info/sargis/gedi/InterchangeMessage.java

package info.sargis.gedi;

import info.sargis.gedi.model.FunctionalGroupPayload;
import info.sargis.gedi.model.InterchangePayload;
import info.sargis.gedi.model.MessagePayload;
import info.sargis.gedi.model.UserSegment;

public interface InterchangeMessage

{ String getEol(); String getCompDataSeparator(); String getDataElemSeparator(); String getDecimalNotation(); String getReleaseIndicator(); String getReserved(); String getSegmentTerminator(); InterchangePayload createInterchangePayload(); FunctionalGroupPayload createFunctionalGroupPayload(); MessagePayload createMessagePayload(); UserSegment createUserSegment(String tagName); }

here is my class referred in InterchangeMessage interface

src/main/groovy/info/sargis/gedi/model/InterchangePayload.groovy
src/main/groovy/info/sargis/gedi/model/MessagePayload.groovy
src/main/groovy/info/sargis/gedi/model/FunctionalGroupPayload.groovy
src/main/groovy/info/sargis/gedi/model/UserSegment.groovy

here is build.gradle

apply plugin: 'idea'
apply plugin: 'code-quality'
apply plugin: 'groovy'

sourceCompatibility = 1.6

repositories {
mavenCentral()
}

dependencies {
groovy group: 'org.codehaus.groovy', name: 'groovy-all', version: '1.7.5'
groovy group: 'org.slf4j', name: 'slf4j-api', version: '1.6.1'

testCompile group: 'org.testng', name: 'testng', version: '5.14.1'
testRuntime group: 'ch.qos.logback', name: 'logback-core', version: '0.9.26'
testRuntime group: 'ch.qos.logback', name: 'logback-classic', version: '0.9.26'
}

test {
useTestNG()
}

and here is error:

sargis@sargis:~/sources/gedi> gradle clean build
:clean
:compileJava
/home/sargis/sources/gedi/src/main/java/info/sargis/gedi/InterchangeMessage.java:3: cannot find symbol
symbol : class FunctionalGroupPayload
location: package info.sargis.gedi.model
import info.sargis.gedi.model.FunctionalGroupPayload;
^
/home/sargis/sources/gedi/src/main/java/info/sargis/gedi/InterchangeMessage.java:4: cannot find symbol
symbol : class InterchangePayload
location: package info.sargis.gedi.model
import info.sargis.gedi.model.InterchangePayload;
^
/home/sargis/sources/gedi/src/main/java/info/sargis/gedi/InterchangeMessage.java:5: cannot find symbol
symbol : class MessagePayload
location: package info.sargis.gedi.model
import info.sargis.gedi.model.MessagePayload;
^
/home/sargis/sources/gedi/src/main/java/info/sargis/gedi/InterchangeMessage.java:6: cannot find symbol
symbol : class UserSegment
location: package info.sargis.gedi.model
import info.sargis.gedi.model.UserSegment;
^
/home/sargis/sources/gedi/src/main/java/info/sargis/gedi/InterchangeMessage.java:31: cannot find symbol
symbol : class InterchangePayload
location: interface info.sargis.gedi.InterchangeMessage
InterchangePayload createInterchangePayload();
^
/home/sargis/sources/gedi/src/main/java/info/sargis/gedi/InterchangeMessage.java:33: cannot find symbol
symbol : class FunctionalGroupPayload
location: interface info.sargis.gedi.InterchangeMessage
FunctionalGroupPayload createFunctionalGroupPayload();
^
/home/sargis/sources/gedi/src/main/java/info/sargis/gedi/InterchangeMessage.java:35: cannot find symbol
symbol : class MessagePayload
location: interface info.sargis.gedi.InterchangeMessage
MessagePayload createMessagePayload();
^
/home/sargis/sources/gedi/src/main/java/info/sargis/gedi/InterchangeMessage.java:37: cannot find symbol
symbol : class UserSegment
location: interface info.sargis.gedi.InterchangeMessage
UserSegment createUserSegment(String tagName);
^
8 errors

FAILURE: Build failed with an exception.

  • Where:
    Build file '/home/sargis/sources/gedi/build.gradle'
  • What went wrong:
    Execution failed for task ':compileJava'.
    Cause: Compile failed; see the compiler error output for details.
  • Try:
    Run with -s or -d option to get more details. Run with -S option to get the full (very verbose) stacktrace.

BUILD FAILED

Total time: 5.344 secs
sargis@sargis:~/sources/gedi>

Please note I am able to compile/build my project with IntelliJ



 Comments   
Comment by Adam Murdoch [ 28/Oct/10 ]

By default, Gradle does joint compilation only for Java and Groovy source under src/main/groovy. Anything in src/main/java is compiled on its own and cannot depend on Groovy classes.

This is arguably a pretty confusing default, and one which we should fix.

In the meantime, you can configure the groovy plugin to include src/main/java in joint compilation:

sourceSets.main.java.srcDirs = []
sourceSets.main.groovy.srcDir 'src/main/java'
Comment by Sargis Harutyunyan [ 30/Oct/10 ]

Thanks for explanation and for your solution, it works nice.

Comment by Mauro Molinari [ 10/Nov/11 ]

@Adam: if you intend to change the current default behaviour, please include a clean and simple way to fall back to the current one.

I mean, we have projects with hundreds of Java classes and few Groovy classes, in which Java classes do not require Groovy classes. Making Gradle do joint compilation by default on src/main/java too would lead to a performance penalty in the build process in our case.

IMHO once one knows that joint compilation is done ONLY in src/main/groovy by default, moving his/her Java code to src/main/groovy or changing sourceSets definition in build.gradle when joint compilation is needed should not be a big trouble... So I personally absolutely prefer the current behaviour.

Comment by Vaclav Tolar [ 11/Jul/12 ]

I have also hit this problem. Provided workaround works for me too.
Will be this issue fixed somehow or the current behaviour will stay unchanged?

Comment by Peter Niederwieser [ 14/Jul/12 ]

The current behavior is how it was designed to work, and we don't currently have plans to change it. It's more likely that we'll revisit this topic once Groovy fundamentally changes its joint compilation approach (which is scheduled for Groovy 3.0).

Comment by Suresh Khatri [ 20/Sep/12 ]

@Adam: current design is the right approach for most projects. There is always the option to use src/main/groovy for all java + groovy code and is never going to be a problem.

Also the expected behaviour of having java and groovy compiled together in src/main/java is merely a configuration change as mentioned above. Anything more than that probably warrants its own sub project.

Also what of the compile*Scala tasks and any other future support for other languages. With polyglot programming becoming popular by the day in projects, any coupling of java and groovy should be made with considerations for other languages as well.

Comment by Janunsz Sidor [ 02/Jul/14 ]

What in case of using packages from com.sun…. With recommended strategy of joint compilation(sourceSets.main.groovy.srcDir 'src/main/java') and using workaround for com.sun :
options.compilerArgs << '-XDignore.symbol.file=true'
options.fork = true
options.forkOptions.executable = 'javac'

doesn't work. I had to move dependency of com.sun into java files with different source root, which cannot depend on groovy files.
So I had to make it like that:
sourceSets.main.java.srcDirs = ['src/main/javaplain'] - here are only which depends on com.sun
sourceSets.main.groovy.srcDirs += ["src/main/java"] - rest
Thanks for any other ideas

Comment by Benjamin Muschko [ 15/Nov/16 ]

As announced on the Gradle blog we are planning to completely migrate issues from JIRA to GitHub.

We intend to prioritize issues that are actionable and impactful while working more closely with the community. Many of our JIRA issues are inactionable or irrelevant. We would like to request your help to ensure we can appropriately prioritize JIRA issues you’ve contributed to.

Please confirm that you still advocate for your JIRA issue before December 10th, 2016 by:

  • Checking that your issues contain requisite context, impact, behaviors, and examples as described in our published guidelines.
  • Leave a comment on the JIRA issue or open a new GitHub issue confirming that the above is complete.

We look forward to collaborating with you more closely on GitHub. Thank you for your contribution to Gradle!

Comment by Benjamin Muschko [ 10/Feb/17 ]

Thanks again for reporting this issue. We haven't heard back from you after our inquiry from November 15th. We are closing this issue now. Please create an issue on GitHub if you still feel passionate about getting it resolved.

Generated at Wed Jun 30 11:49:16 CDT 2021 using Jira 8.4.2#804003-sha1:d21414fc212e3af190e92c2d2ac41299b89402cf.