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

:prepareKotlinBuildScriptModel Task fails in a Java project #14889

Closed
spectrumIG opened this issue Oct 16, 2020 · 36 comments
Closed

:prepareKotlinBuildScriptModel Task fails in a Java project #14889

spectrumIG opened this issue Oct 16, 2020 · 36 comments

Comments

@spectrumIG
Copy link

Expected Behavior

With Android Studio 4.1 when updating to Gradle Plugin 4.1.0 and Gradle 6.5 I expect to build smoothly a previously building a full JAVA project

Current Behavior

When try to build an old Java project which build with previous configuration Gradle build starts to complain about a Gradle task :prepareKotlinBuildScriptModel which fails without any possibility of doing nothing

Context

I'm trying to build a normal non Kotlin project. The project is made by the app module and a second module which is a ndk/c++/java library. The project was perfectly building before updating plugin and Gradle versions.

Steps to Reproduce

-Take Android Studio 4.0 with plugin 4.0.1 and Gradle 6.1.

  • Import a full Java project with no error.
  • Build and run
  • Update AS to 4.1, Gradle plugin to 4.1.0 and Gradle 6.5
  • Build again after clean
  • The task fail

Your Environment

Android Studio 4.1, Gradle 6.5, Gradle plugin 4.1.0

S.O.: Ubuntu 20.04 LTS

@eskatos
Copy link
Member

eskatos commented Oct 16, 2020

Hi @spectrumIG,
Could you please describe how it fails?
A copy of the failure log would help

@spectrumIG
Copy link
Author

spectrumIG commented Oct 16, 2020

@eskatos ok this is the log of the build:
``FAILURE: Build failed with an exception.

  • What went wrong:
    Task 'prepareKotlinBuildScriptModel' not found in project ':WI'.

  • Try:
    Run gradle tasks to get a list of available tasks. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

  • Exception is:
    org.gradle.execution.TaskSelectionException: Task 'prepareKotlinBuildScriptModel' not found in project ':WI'.
    at org.gradle.execution.TaskSelector.getSelection(TaskSelector.java:117)
    at org.gradle.execution.TaskSelector.getSelection(TaskSelector.java:82)
    at org.gradle.execution.commandline.CommandLineTaskParser.parseTasks(CommandLineTaskParser.java:42)
    at org.gradle.execution.TaskNameResolvingBuildConfigurationAction.configure(TaskNameResolvingBuildConfigurationAction.java:46)
    at org.gradle.execution.DefaultBuildConfigurationActionExecuter.configure(DefaultBuildConfigurationActionExecuter.java:58)
    at org.gradle.execution.DefaultBuildConfigurationActionExecuter.access$200(DefaultBuildConfigurationActionExecuter.java:26)
    at org.gradle.execution.DefaultBuildConfigurationActionExecuter$2.proceed(DefaultBuildConfigurationActionExecuter.java:66)
    at org.gradle.execution.DefaultTasksBuildExecutionAction.configure(DefaultTasksBuildExecutionAction.java:45)
    at org.gradle.execution.DefaultBuildConfigurationActionExecuter.configure(DefaultBuildConfigurationActionExecuter.java:58)
    at org.gradle.execution.DefaultBuildConfigurationActionExecuter.access$200(DefaultBuildConfigurationActionExecuter.java:26)
    at org.gradle.execution.DefaultBuildConfigurationActionExecuter$2.proceed(DefaultBuildConfigurationActionExecuter.java:66)
    at org.gradle.execution.ExcludedTaskFilteringBuildConfigurationAction.configure(ExcludedTaskFilteringBuildConfigurationAction.java:48)
    at org.gradle.execution.DefaultBuildConfigurationActionExecuter.configure(DefaultBuildConfigurationActionExecuter.java:58)
    at org.gradle.execution.DefaultBuildConfigurationActionExecuter.access$200(DefaultBuildConfigurationActionExecuter.java:26)
    at org.gradle.execution.DefaultBuildConfigurationActionExecuter$1.run(DefaultBuildConfigurationActionExecuter.java:44)
    at org.gradle.internal.Factories$1.create(Factories.java:26)
    at org.gradle.api.internal.project.DefaultProjectStateRegistry.withLenientState(DefaultProjectStateRegistry.java:134)
    at org.gradle.api.internal.project.DefaultProjectStateRegistry.withLenientState(DefaultProjectStateRegistry.java:126)
    at org.gradle.execution.DefaultBuildConfigurationActionExecuter.select(DefaultBuildConfigurationActionExecuter.java:40)
    at org.gradle.initialization.DefaultTaskExecutionPreparer.prepareForTaskExecution(DefaultTaskExecutionPreparer.java:38)
    at org.gradle.initialization.BuildOperatingFiringTaskExecutionPreparer$CalculateTaskGraph.populateTaskGraph(BuildOperatingFiringTaskExecutionPreparer.java:117)
    at org.gradle.initialization.BuildOperatingFiringTaskExecutionPreparer$CalculateTaskGraph.run(BuildOperatingFiringTaskExecutionPreparer.java:68)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:395)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:387)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$1.execute(DefaultBuildOperationExecutor.java:157)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:242)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:150)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:84)
    at org.gradle.internal.operations.DelegatingBuildOperationExecutor.run(DelegatingBuildOperationExecutor.java:31)
    at org.gradle.initialization.BuildOperatingFiringTaskExecutionPreparer.prepareForTaskExecution(BuildOperatingFiringTaskExecutionPreparer.java:56)
    at org.gradle.initialization.DefaultGradleLauncher.prepareTaskExecution(DefaultGradleLauncher.java:227)
    at org.gradle.initialization.DefaultGradleLauncher.doClassicBuildStages(DefaultGradleLauncher.java:159)
    at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:140)
    at org.gradle.initialization.DefaultGradleLauncher.executeTasks(DefaultGradleLauncher.java:120)
    at org.gradle.internal.invocation.GradleBuildController$1.create(GradleBuildController.java:74)
    at org.gradle.internal.invocation.GradleBuildController$1.create(GradleBuildController.java:67)
    at org.gradle.internal.work.DefaultWorkerLeaseService.withLocks(DefaultWorkerLeaseService.java:180)
    at org.gradle.internal.work.StopShieldingWorkerLeaseService.withLocks(StopShieldingWorkerLeaseService.java:40)
    at org.gradle.internal.invocation.GradleBuildController.doBuild(GradleBuildController.java:67)
    at org.gradle.internal.invocation.GradleBuildController.run(GradleBuildController.java:56)
    at org.gradle.tooling.internal.provider.runner.ClientProvidedPhasedActionRunner.run(ClientProvidedPhasedActionRunner.java:60)
    at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.java:35)
    at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.java:35)
    at org.gradle.launcher.exec.BuildOutcomeReportingBuildActionRunner.run(BuildOutcomeReportingBuildActionRunner.java:63)
    at org.gradle.tooling.internal.provider.ValidatingBuildActionRunner.run(ValidatingBuildActionRunner.java:32)
    at org.gradle.launcher.exec.BuildCompletionNotifyingBuildActionRunner.run(BuildCompletionNotifyingBuildActionRunner.java:39)
    at org.gradle.launcher.exec.RunAsBuildOperationBuildActionRunner$3.call(RunAsBuildOperationBuildActionRunner.java:51)
    at org.gradle.launcher.exec.RunAsBuildOperationBuildActionRunner$3.call(RunAsBuildOperationBuildActionRunner.java:45)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$CallableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:409)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$CallableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:399)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$1.execute(DefaultBuildOperationExecutor.java:157)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:242)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:150)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.call(DefaultBuildOperationExecutor.java:94)
    at org.gradle.internal.operations.DelegatingBuildOperationExecutor.call(DelegatingBuildOperationExecutor.java:36)
    at org.gradle.launcher.exec.RunAsBuildOperationBuildActionRunner.run(RunAsBuildOperationBuildActionRunner.java:45)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter$1.transform(InProcessBuildActionExecuter.java:50)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter$1.transform(InProcessBuildActionExecuter.java:47)
    at org.gradle.composite.internal.DefaultRootBuildState.run(DefaultRootBuildState.java:80)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:47)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:31)
    at org.gradle.launcher.exec.BuildTreeScopeBuildActionExecuter.execute(BuildTreeScopeBuildActionExecuter.java:42)
    at org.gradle.launcher.exec.BuildTreeScopeBuildActionExecuter.execute(BuildTreeScopeBuildActionExecuter.java:28)
    at org.gradle.tooling.internal.provider.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:87)
    at org.gradle.tooling.internal.provider.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:55)
    at org.gradle.tooling.internal.provider.SubscribableBuildActionExecuter.execute(SubscribableBuildActionExecuter.java:60)
    at org.gradle.tooling.internal.provider.SubscribableBuildActionExecuter.execute(SubscribableBuildActionExecuter.java:38)
    at org.gradle.tooling.internal.provider.SessionScopeBuildActionExecuter.execute(SessionScopeBuildActionExecuter.java:68)
    at org.gradle.tooling.internal.provider.SessionScopeBuildActionExecuter.execute(SessionScopeBuildActionExecuter.java:38)
    at org.gradle.tooling.internal.provider.GradleThreadBuildActionExecuter.execute(GradleThreadBuildActionExecuter.java:37)
    at org.gradle.tooling.internal.provider.GradleThreadBuildActionExecuter.execute(GradleThreadBuildActionExecuter.java:26)
    at org.gradle.tooling.internal.provider.StartParamsValidatingActionExecuter.execute(StartParamsValidatingActionExecuter.java:60)
    at org.gradle.tooling.internal.provider.StartParamsValidatingActionExecuter.execute(StartParamsValidatingActionExecuter.java:32)
    at org.gradle.tooling.internal.provider.SessionFailureReportingActionExecuter.execute(SessionFailureReportingActionExecuter.java:56)
    at org.gradle.tooling.internal.provider.SessionFailureReportingActionExecuter.execute(SessionFailureReportingActionExecuter.java:42)
    at org.gradle.tooling.internal.provider.SetupLoggingActionExecuter.execute(SetupLoggingActionExecuter.java:48)
    at org.gradle.tooling.internal.provider.SetupLoggingActionExecuter.execute(SetupLoggingActionExecuter.java:32)
    at org.gradle.launcher.daemon.server.exec.ExecuteBuild.doBuild(ExecuteBuild.java:68)
    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:37)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:104)
    at org.gradle.launcher.daemon.server.exec.WatchForDisconnection.execute(WatchForDisconnection.java:39)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:104)
    at org.gradle.launcher.daemon.server.exec.ResetDeprecationLogger.execute(ResetDeprecationLogger.java:29)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:104)
    at org.gradle.launcher.daemon.server.exec.RequestStopIfSingleUsedDaemon.execute(RequestStopIfSingleUsedDaemon.java:35)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:104)
    at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.create(ForwardClientInput.java:78)
    at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.create(ForwardClientInput.java:75)
    at org.gradle.util.Swapper.swap(Swapper.java:38)
    at org.gradle.launcher.daemon.server.exec.ForwardClientInput.execute(ForwardClientInput.java:75)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:104)
    at org.gradle.launcher.daemon.server.exec.LogAndCheckHealth.execute(LogAndCheckHealth.java:55)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:104)
    at org.gradle.launcher.daemon.server.exec.LogToClient.doBuild(LogToClient.java:63)
    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:37)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:104)
    at org.gradle.launcher.daemon.server.exec.EstablishBuildEnvironment.doBuild(EstablishBuildEnvironment.java:82)
    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:37)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:104)
    at org.gradle.launcher.daemon.server.exec.StartBuildOrRespondWithBusy$1.run(StartBuildOrRespondWithBusy.java:52)
    at org.gradle.launcher.daemon.server.DaemonStateCoordinator$1.run(DaemonStateCoordinator.java:297)
    at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
    at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:48)
    at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:56)

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

BUILD FAILED in 12s

Thanks a lot.

@eskatos
Copy link
Member

eskatos commented Oct 16, 2020

@spectrumIG, is it happening when importing a subproject in your IDE or the whole build? Just trying to rule out some cases.

Also, what version of the IntelliJ/Studio Kotlin Plugin do you have installed in your IDE?

@spectrumIG
Copy link
Author

@eskatos it happens when building the whole project. Version are: Android Studio 4.1 (updated yesterday). Kotlin plugin -> 1.4.10-release-Studio4.1-1. Thanks

@eskatos
Copy link
Member

eskatos commented Oct 16, 2020

Thanks.

About the confusion, this task has nothing to do with the fact that your project doesn't have Kotlin sources. It's about supporting the edition of .gradle.kts scripts in the IDE. The fact that you have such scripts or not can't be detected upfront. This task needs to run always. When you have no .gradle.kts scripts it's doesn't do anything.

That task is always registered on the root project.

The error message you get suggests that the IDE tries to execute it on the :WI subproject. but that can't work as that task only exist on the root project. It's the first time I read about this behavior.

@NataliaUkhorskaya, any idea what could happen here?

@spectrumIG
Copy link
Author

@eskatos Yes, I perfectly understand. Infact the strange thing that happens is that the SAME task runs smoothly,meaning doing absolutley nothing as expected, if the gradle and gradle plugin are mantained at previous versions.
About modules: i noticed a strange thing about Android Studio 4.1. It seems it had changed how module are referenced. i mean: in run configuration i now see Android.WII as a module but since previous release was just WII. Also looking at modified files it seems it changed some IDE conf file. Don't know, maybe has nothing to do about the task...

@KibiH
Copy link

KibiH commented Oct 18, 2020

Hi @spectrumIG I think I have the same problem as you, did you fix it? How?
I have a simple example project which I have imported from Oculus, and this is the error I receive:
Task 'prepareKotlinBuildScriptModel' not found in project ':VrSamples:VrCubeWorld_NativeActivity:Projects:Android'.

@snrostov
Copy link

@vladimirdolzhenko please take a look

@spectrumIG
Copy link
Author

@KibiH actually I didn't. I simply downgrade Gradle version to 6.1.1 and Gradle Android plugin to 4.0.1 and the task suddenly start to pass again.

@ausatiy
Copy link

ausatiy commented Oct 19, 2020

@spectrumIG , do you observe the issue only if some preconditions are met (e.g. run from AS, do some steps) or one could just checkout source code and reproduce the issue?
Do you have any kind of open source code where the issue could be reproduced?

@ghost
Copy link

ghost commented Oct 19, 2020

Same issue happening for me, Also had to downgrade to 4.0.2 Studio to make it work. 😢

@spectrumIG
Copy link
Author

@ausatiy I'm sorry but actually I don't know. I mean, I only tried with this project because is the only project i use at work which has java code. i mean, i didn't even try to put on an actual kotlin project. So, I'm sorry but I don't know. I'm quite sure that java language is a prerequisite though.

@ausatiy
Copy link

ausatiy commented Oct 19, 2020

Thank you.
Actually, any piece of information could help. E.g. project where the issue was reproduced, was it reproduced when running from AS or running from console also allows to reproduce it.

I've failed to reproduce the issue just by using Kotlin from master (~1.4.30, but it should not be quite different from 1.4.10 which is mentioned earlier) + AS 4.1 + Gradle 6.5 and quite simple Android+java project.

@SamCarmichael36
Copy link

SamCarmichael36 commented Oct 19, 2020

Hey spectrumIG,
What a coincidence, I had the same problem! I am even using the NDK here and got the same problem as when you were using Java so it's even more widespread. I am developing an OpenGL VR program (after years of developing shutter glasses games) and when updating the gradle a few days ago, that's when the error started occurring.
You may be able to add the task to the gradle as shown in these instructions:
But I could not downgrade the version like you said, I tried adding strictly to the build.gradle (then it has some options and says cannot sync), grade-wrapper.properties (distributionUrl), going to gradle settings for my own downloaded gradle version (but then it automatically updates it again) or says gradle version 6.5 minimum is required. How did you lower the version successfully? This is a definite problem with Google and Jetbrains trying to get you locked into a connection with them in order to sync and requiring the newest version for no reason. And I have even had other similar problems with the gradle happen before especially about when they switched from Java to NDK. I will try to stop updating my whole program in the future but I wonder if that will even work.

@SamCarmichael36
Copy link

SamCarmichael36 commented Oct 22, 2020

Alright, I finally fixed the problem and got everything working in the newest versions! There were multiple build.gradle files in the Teapots sample, one for the main Teapots projects and more for the subprojects. I just opened the build.gradle for classic-teapot which was the subproject I was editing and added this line to the build.gradle file (not inside any other function, as its own function):
tasks.register("prepareKotlinBuildScriptModel"){}
This had tricked the program into thinking that the task was there. I had found the task in the gradle but it was not classified under this exact project (so it was looking for it in the wrong spot).
classic-teapot:preDebugUnitTestBuild
prepareKotlinBuildScriptModel
classic-teapot:prepareLintJarForPublish
In fact, this was the only task out of 250 without my project name before it like the 1st and 3rd shown here.

@heechokim
Copy link

heechokim commented Oct 22, 2020

@SamCarmichael36 Thank you so much😃
I fixed this problem by adding tasks.register("prepareKotlinBuildScriptModel"){} to build.gradle(Module.app) file.
Thank you😃

@eskatos
Copy link
Member

eskatos commented Oct 22, 2020

Could anybody reproducing this problem share a build and instructions to reproduce?
If you can't share your project publicly maybe you could consider sharing it privately.
It's good to have a workaround but we should understand what's going on and find a fix.

@SamCarmichael36
Copy link

No problem choheeis! eskatos: here is a link to the teapot sample I was using:
https://github.com/android/ndk-samples/tree/master/teapots
There were no other complications that I had to cause the problem. It was simply caused by the recent update about a week ago when they had added some Kotlin features.

@KibiH
Copy link

KibiH commented Oct 27, 2020

Thanks @choheeis your fix also worked for me!

@eskatos
Copy link
Member

eskatos commented Oct 30, 2020

Thank you @SamCarmichael36 for the reproducer. Unfortunately I can't reproduce with it. I was able to import the build in IntelliJ without any issue.

image

@eskatos
Copy link
Member

eskatos commented Oct 30, 2020

Relevant comment on the corresponding Youtrack issue at https://youtrack.jetbrains.com/issue/KT-37892#focus=Comments-27-4474258.0-0

I now open the root project instead of the child project. We use gradle subprojects. It seems that how Intellij handles subprojects have changed slightly. Previously I was forced to open the subprojects separately to get stuff to work. Now I have to open the parent project. If I open the subproject I still get this error.

This seems to imply that the problem happens when you open a subproject in IDEA instead of the root project/settings.

@ausatiy or @nskvortsov, any idea what could cause that in IDEA or its Kotlin plugin?

@nskvortsov
Copy link
Contributor

Not sure about what is going on with the prepareKotlinBuildScriptModel task, but linking a subproject of a multimodule project indeed may cause issues and is not recommended. Project model will anyway be generated for the whole project, but the root project path may be wrong for subsequent operations.

@eskatos
Copy link
Member

eskatos commented Oct 30, 2020

prepareKotlinBuildScriptModel only exists on the root project and IDEA Kotlin plugin runs it during build import/sync.

linking a subproject of a multimodule project indeed may cause issues and is not recommended

Shouldn't IDEA import the whole build when pointed at a subproject build script? This would prevent hard to troubleshoot issues.
FTR that's exactly what Buildship do.

@SamCarmichael36
Copy link

Thanks for trying it, eskatos. I'm surprised that it did not produce the same error, but I am using Android Studio in Ubuntu 20.04.1 LTS also.

@adam-hurwitz
Copy link

adam-hurwitz commented Jan 24, 2021

See: StackOverflow post solution Task 'prepareKotlinBuildScriptModel' not found in project ':app'

@saeedeyvazy
Copy link

Add this line to build.gradle file:

task prepareKotlinBuildScriptModel {
}

@theAkito
Copy link

Adding the following to my build.gradle.kts file fixed this unnecessary issue:

tasks.register("prepareKotlinBuildScriptModel") {}

The solution from the previous comment only works for obsolete build.gradle files.

csieflyman added a commit to csieflyman/multi-projects-architecture-with-Ktor that referenced this issue Aug 18, 2021
@abcfy2
Copy link

abcfy2 commented Nov 24, 2021

Same issue, still happened in gradle 7.3 with IDEA Intellij. Any update?

@ITachiLab
Copy link

ITachiLab commented Dec 7, 2021

In my case the problem was that I had a root Gradle project with multiple subprojects included in root's settings.gradle, while simultaneously having one of the subprojects being added to IntelliJ's Gradle projects manually.

In other words: if you have a hierarchical Gradle project, make sure that when you open up the Gradle projects panel in IntelliJ, all subprojects are listed as children of the root. I had one subproject dangling, listed as sibling project of the root. I simply right clicked on it and chose "Unlink Gradle Project".

IntelliJ automatically adds projects listed in settings.gradle, you don't have to add them manually by right clicking on a build.gradle and choosing "Link Gradle Project" (that's what I did and it was a mistake).

@ljacomet
Copy link
Member

Closing for now as no valid reproducer was shared and last comments indicate that this is an issue with opening a subproject directly in Idea.

If you have a reproducer that points at a Gradle problem and is not caused by the above setup, please share and we can re-open.

@tudor07
Copy link

tudor07 commented Jul 22, 2022

I'm having the same issue

@Elonnn
Copy link

Elonnn commented Aug 18, 2022

In my case the problem was that I had a root Gradle project with multiple subprojects included in root's settings.gradle, while simultaneously having one of the subprojects being added to IntelliJ's Gradle projects manually.

In other words: if you have a hierarchical Gradle project, make sure that when you open up the Gradle projects panel in IntelliJ, all subprojects are listed as children of the root. I had one subproject dangling, listed as sibling project of the root. I simply right clicked on it and chose "Unlink Gradle Project".

IntelliJ automatically adds projects listed in settings.gradle, you don't have to add them manually by right clicking on a build.gradle and choosing "Link Gradle Project" (that's what I did and it was a mistake).

Me as well. I fixed it by deleting the unwanted GradleProjectSettings in the gradle.xml file under .idea folder in the root.

@pilot911
Copy link

pilot911 commented Oct 4, 2022

Me as well. I fixed it by deleting the unwanted GradleProjectSettings in the gradle.xml file under .idea folder in the root.

Thanks! Helped me!

@LVMVRQUXL
Copy link

LVMVRQUXL commented Nov 1, 2022

In my case the problem was that I had a root Gradle project with multiple subprojects included in root's settings.gradle, while simultaneously having one of the subprojects being added to IntelliJ's Gradle projects manually.

In other words: if you have a hierarchical Gradle project, make sure that when you open up the Gradle projects panel in IntelliJ, all subprojects are listed as children of the root. I had one subproject dangling, listed as sibling project of the root. I simply right clicked on it and chose "Unlink Gradle Project".

IntelliJ automatically adds projects listed in settings.gradle, you don't have to add them manually by right clicking on a build.gradle and choosing "Link Gradle Project" (that's what I did and it was a mistake).

This solution helped me fix the same issue. Thanks a lot @ITachiLab!

@Agadsara
Copy link

@spectrumIG So I got the same issue as yours. As the scenario is let my project name is ABC and the sub project name contains xyz. So I got this error when I import the sub project. After that I imported the ABC project and its perfectly synced.

@aterilio
Copy link

aterilio commented May 14, 2023

In my case, the following did not work :

tasks.register("prepareKotlinBuildScriptModel"){}

So I disabled the Kotlin plugin, and the problem was solved.
(Because I don't use Kotlin, and I use only IntelliJ, not Android Studio.)
Refer to the following link : https://stackoverflow.com/a/68825390/15713049

WARN! If you are using Android Studio, you should NOT disable the Kotlin plugin.
Also refer to the following link : https://stackoverflow.com/a/72767281/15713049

(I'm on the latest IntelliJ 2023.1.1 Ultimate Edition.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests