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

error: Unexpected error: Attempt to recreate a file for type com.example.$DemoTest$Definition #6536

Closed
natros opened this issue Nov 19, 2021 · 9 comments · Fixed by gradle/gradle#19067
Labels
status: awaiting third-party Awaiting changes to a third party library type: bug Something isn't working

Comments

@natros
Copy link

natros commented Nov 19, 2021

Expected Behavior

Compile without errors

Actual Behaviour

> Task :compileJava
Note: Creating bean classes for 3 type elements

> Task :processResources UP-TO-DATE
> Task :classes

> Task :compileTestJava FAILED
Note: Creating bean classes for 1 type elements
error: Unexpected error: Attempt to recreate a file for type com.example.$DemoTest$Definition
1 error

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':compileTestJava'.
> 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.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

Steps To Reproduce

  1. git clone git@github.com:natros/mn-demo.git
  2. ./gradlew --console=verbose testClasses
  3. gsed 's/"auth"/"auth2"/' -i src/main/java/com/example/ApiConfiguration.java
  4. ./gradlew --console=verbose testClasses

Environment Information

  • macOS BigSur
  • java --version
    openjdk 17.0.1 2021-10-19 LTS
    OpenJDK Runtime Environment Zulu17.30+15-CA (build 17.0.1+12-LTS)
    OpenJDK 64-Bit Server VM Zulu17.30+15-CA (build 17.0.1+12-LTS, mixed mode, sharing)
  • gradle 7.3

Example Application

https://github.com/natros/mn-demo

Version

3.1.4

@graemerocher
Copy link
Contributor

This looks like another Gradle 7.3 incremental compilation bug. /cc @melix

Workaround is to use 7.2

@graemerocher graemerocher added type: bug Something isn't working status: awaiting third-party Awaiting changes to a third party library labels Nov 19, 2021
@melix
Copy link
Contributor

melix commented Nov 19, 2021

mmm, that's strange, could it be that the fix @oehme worked on didn't make it into 7.3?

@graemerocher
Copy link
Contributor

Seems it did but this is a different case? gradle/gradle#18840

@oehme
Copy link

oehme commented Nov 19, 2021

I'll have a look.

@oehme
Copy link

oehme commented Nov 19, 2021

@natros I've verified my fix with your sample. Can you check out gradle/gradle#19067, run gradle install and let me know whether this fixes your real project?

@natros
Copy link
Author

natros commented Nov 19, 2021

@oehme I can confirm it works.

Thanks for the quick fix.

@natros
Copy link
Author

natros commented Nov 20, 2021

Hello @oehme

I come across a new case that took me a long time to reproduce.

Steps

  1. git clone git@github.com:natros/nm-demo2.git
  2. cd nm-demo2
  3. ./compile.sh

Note: with linux edit compile.sh and replace gsed with sed

After a few iterations you should see

> Task :compileJava FAILED
Note: Creating bean classes for 2 type elements
error: Unexpected error: Attempt to recreate a file for type com.example.$ApiFactory$Api0$Definition$Reference
1 error

I'm using gradle with your patch

 gradle --version

------------------------------------------------------------
Gradle 7.4-20211120120447+0000
------------------------------------------------------------

Build time:   2021-11-20 12:04:47 UTC
Revision:     0430712b7a96f22bf0b0c11d7f04e64b67c49867

Kotlin:       1.5.31
Groovy:       3.0.9
Ant:          Apache Ant(TM) version 1.10.11 compiled on July 10 2021
JVM:          17.0.1 (Azul Systems, Inc. 17.0.1+12-LTS)
OS:           Mac OS X 11.5 x86_64

With gradle 7.2 I cannot reproduce de error
With 7.3 I get the error on the first iteration
With 7.4 (compiled with you patch) I get the error after a few iterations

@oehme
Copy link

oehme commented Nov 22, 2021

Found and fixed that issue as well, same pull request.

@natros
Copy link
Author

natros commented Nov 22, 2021

Seems to be working 😀

Once again, thank you.

oehme added a commit to oehme/gradle that referenced this issue Nov 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: awaiting third-party Awaiting changes to a third party library type: bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants