[GRADLE-2574] "Unable to resolve class" after moving a class from src/main/groovy to src/main/java Created: 27/Nov/12  Updated: 10/Feb/17  Resolved: 10/Feb/17

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

Type: Bug
Reporter: Gradle Forums Assignee: Unassigned
Resolution: Won't Fix Votes: 1

Issue Links:
Duplicate
Duplicated by GRADLE-1034 Compilation failure when java source ... Resolved

 Description   

I moved a couple files from src/main/groovy/ to src/main/java/, followed by changing the associated file suffixes from .groovy to .java. My project would not build until I removed the .gradle/ cache in the project current working directory. The compiler complained that it could not find the files/classes that had moved.

Is this to be expected?



 Comments   
Comment by Gradle Forums [ 27/Nov/12 ]

This shouldn't happen. Can you provide the exact error message, stack trace, etc.?

Comment by Gradle Forums [ 27/Nov/12 ]

Here is the error message from my console:

/Users/petrovic/Projects/acme/qa/lib/atf-core/geb-browser-parent/geb-dpsbrowser/src/main/groovy/com/acme/qa/dpsbrowser/DPSBrowserImpl.groovy: 162: unable to resolve class ServiceType
@ line 162, column 73.
imit(String partnerShortName, ServiceTyp
^

I will try to reproduce in a test project. If I cannot, this is all I can offer at the moment.

Comment by Gradle Forums [ 27/Nov/12 ]

Ok, I am able to reproduce this in a test project.

Here is my console output:

mb:gradle-rename-enum> find .
.
./build.gradle
./src
./src/main
./src/main/groovy
./src/main/groovy/somepackage
./src/main/groovy/somepackage/AScript.groovy
./src/main/groovy/somepackage/SomeEnum.groovy
./src/main/java
./src/main/java/somepackage

mb:gradle-rename-enum> gradle -q build

mb:gradle-rename-enum> mv -v src/main/groovy/somepackage/SomeEnum.groovy src/main/java/somepackage/SomeEnum.java
src/main/groovy/somepackage/SomeEnum.groovy -> src/main/java/somepackage/SomeEnum.java

mb:gradle-rename-enum> gradle -q build
startup failed:
/Users/petrovic/Projects/gradle-rename-enum/src/main/groovy/somepackage/AScript.groovy: 6: unable to resolve class SomeEnum
@ line 6, column 18.
SomeEnum someEnum = SomeEnum.A
^

1 error

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ':compileGroovy'.
    > Compilation failed; see the compiler error output for details.
  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

mb:gradle-rename-enum> rm -rf .gradle/

mb:gradle-rename-enum> gradle -q build # no problems

Here is my build script:

apply plugin: 'groovy'

repositories {
mavenCentral()
}

dependencies {
groovy group: 'org.codehaus.groovy', name: 'groovy-all', version: '2.0.5'
}

And here are the source files:

An enum that I move from src/main/groovy to src/main/java:

package somepackage;

public enum SomeEnum {
A, B
}

The client code:

package somepackage

class AScript {

def foo() {
SomeEnum someEnum = SomeEnum.A
}
}

My Gradle version:

gradle -v

------------------------------------------------------------
Gradle 1.2
------------------------------------------------------------

Gradle build time: Wednesday, September 12, 2012 10:46:02 AM UTC
Groovy: 1.8.6
Ant: Apache Ant(TM) version 1.8.4 compiled on May 22 2012
Ivy: 2.2.0
JVM: 1.6.0_37 (Apple Inc. 20.12-b01-434)
OS: Mac OS X 10.6.8 x86_64

Comment by Gradle Forums [ 27/Nov/12 ]

I re-ran the scenario with Gradle 1.3. It behaves the same as 1.2.

Comment by Gradle Forums [ 27/Nov/12 ]

The project on github:

[1]https://github.com/ae6rt/gradle-renam...
----------------------------------------------------------------------------------------
[1] https://github.com/ae6rt/gradle-rename-enum.git

Comment by Adam Murdoch [ 27/Nov/12 ]

Workaround is to run with --rerun-tasks

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 12:25:38 CDT 2021 using Jira 8.4.2#804003-sha1:d21414fc212e3af190e92c2d2ac41299b89402cf.