Unresolved reference JavaVersion in gradle buildSrc IntelliJ - gradle

I am facing a problem with two existing gradle projects that worked fine a couple of months ago but that show now an annoying error in the buildSrc folder, where I use the org.gradle.api.JavaVersion constant.
The project compiles correctly and is imported to IntelliJ. I can also run it so I guess everything is working but of course I don't like to get an error thrown into my face ;)
Here are both example projects:
https://github.com/Quillraven/Quilly-s-Adventure
https://github.com/Quillraven/Dark-Matter
They are both a multi-project with a core, desktop and android project.
In both projects I use a buildSrc folder to define the versions in a common place for the entire project.
For whatever reason, IntelliJ is now showing an error "unresolved reference JavaVersion" in the Dependencies.kt/versions.kt file.
The build.gradle.kts of the buildSrc folder looks like this:
plugins {
`kotlin-dsl`
}
repositories {
jcenter()
}
Does anyone know how to get rid of this error? Is it an IntelliJ issue or something else? Or is the issue on my end ?

This is an Intellij IDEA 2020.2 bug: https://youtrack.jetbrains.com/issue/KT-40683. Dependencies are unresolved in the buildSrc module, when you also have an Android module in the project.
As a possible workaround, please use IDEA 2020.1.

Related

Modules, Gradle Subprojects, and IntelliJ Woes?

I am trying to make use of modules and gradle subprojects and either receive compile time errors or complaints from IntelliJ.
My project structure is as follows:
Root
- settings.gradle
- core
- build.gradle
- desktop
- build.gradle
- src/main/java/module-info.java
The desktop build.gradle file as a requirement on core as:
dependencies {
implementation project(":core")
}
There is no reference to the "core" project in the module-info.java files.
In this configuration, IntelliJ doesn't like usage of classes from the "core" project in the "desktop" project (I see a lot of red), but running gradlew.bat desktop:run works with no issues. Bug with IntelliJ? I am using microsoft's openjdk, but hopefully that doesn't matter.
My best attempt to fix this, was to add a module-info.java file to the core project as well and reference the core project in the desktop project's module-info.java file. Unfortunately this configuration, while making IntelliJ happy, renders me unable to run the desktop from command line anymore. I get errors about the core project being unable to find required modules that are the exact same as the required modules I pull in for the desktop module. I think this might be an error on my part, but I'm not sure how or what to do to fix it.
Would appreciate any insight.
P.S. Of these issues, I think I would prefer to get IntelliJ working with the first setup, because I intend to have this core library be shared between the desktop project and an android project, and while I haven't looked into it yet, I am not sure Android supports new java modules?
I think terminal should be the first priority. If your original setup made it compiled successfully under terminal, then there is no problem in your project. Do not add extra files for just making the IDE happy.
There's still something you can do. The first step is compiling your project successfully under terminal. This step downloads all the necessary dependencies before IntelliJ, reducing the problem scope to IntelliJ's linking and indexing. Then there are some options:
In the Gradle tool window, click the top-left button Refresh all Gradle projects.
Delete all the .idea folders in your project. Then open the root folder of your project via UI or CLI.
Click the invalidate caches/restart in the main menu.
You can also also create a new Gradle multi-module project with command gradle init, and open it with IntelliJ. It should be analyzed by IntelliJ normally. Then you can compare its project structure with yours. Maybe there's something different.
Hope these steps could help you.

IntelliJ Module structure after Gradle import

I a (common) Gradle multi-project build I have a root with four sub-projects. Each with their own build.gradle and a common build.gradle, settings.gradle and gradle.properties in the root folder.
It all builds an works as expected - except for one thing I can't figure out:
When importing the gradle-build into IntelliJ (import from external model) IntelliJ creates two separate modules at root-level. One is marked as a normal Module and one as a Grouped module. It is the latter that surprises me - why is this created? It makes no sense to have in as a module in IntelliJ since it only points to some downloaded jar-files in my .gradle folder. See below picture.
I've create several gradle multi-project builds and worked with IntelliJ for several years - yet I have never seen this nor do I know how to get rid of it..
Andrey said in the comments:
Try 2019.1 RC from jetbrains.com/idea/nextversion The related issue (youtrack.jetbrains.com/issue/IDEA-187917) has been fixed there. See also stackoverflow.com/questions/54036569 as a duplicate.
Which fixes the issue.

Gradle composite build with custom gradle plugin fails in IntelliJ: "Could not find method api() for arguments"

I have a Gradle composite build project which contains a custom Gradle plugin. This project builds fine when using Gradle CLI, but IntelliJ fails.
I tried a few different variations on the plugin version within the resolutionStrategy block: org.test:test-plugin:0.0.1 and test-plugin:test-plugin.gradle.plugin:0.0.1 as described here: https://docs.gradle.org/current/userguide/plugins.html#sec:plugin_markers - both of those work from the CLI; changing to invalid values ("blah:blah") causes a failure.
I've made a sample Github project that contains the code to reproduce, here: https://github.com/mwmitchell/intellij-gradle-plugin-composite-build-bug along with instructions to reproduce and a workaround. The workaround is something that's not really feasible for me, as it requires repeating configuration code (dependencies, plugins etc.) and I have many, many projects that require the same/common configuration.
I would expect IntelliJ to load the project successfully, just like the CLI does. It seems like IntelliJ is loading the sub-project (:project-1:library-a) before the parent (:project-1), such that the java-library is not actually applied to the sub-project when it's evaluated.
Thanks for the sample project! Indeed, it is an issue in IntelliJ IDEA, see this ticket.
Gradle projects can have only one settings.gradle. You can include subproject "library-a" with include 'project-1:library-a' in the main settings.gradle.

kotlin-gradle plugin auto configure error

Module build.gradle code and file structure
Project build.gradle and buildscript code, and reported error
Just getting started with kotlin for android development here. After converting MainActivity to .kt, the kotlin-gradle plugin needs to be configured. IntelliJ offers to do it automatically, but fails with the error:
Cannot find build.gradle for module app.
I know I can configure it myself, but why cant intelliJ find the build.gradle files, they are in the project that was automatically generated by intelliJ itself. Do I have something configured incorrectly?
Any help or insight is appreciated, thank you in advance.
Seems that you are using Idea 2016.1. There is a bug in your tracker: https://youtrack.jetbrains.com/issue/KT-11593
Download the Maven repo from SDK manager, then try to reconfigure the kotlin again.

Use Android Studio With Maven ONLY

All I want to do is use Android Studio without converting to Gradle. I MUST use maven (Client Requirements). How can I accomplish this?
I was able to get this working by opening up the pom.xml file but every time I close the project and reopen it, gradle is forced on me and I can't run anymore. Project layout also changes on me.
When I open up the project the first time using pom.xml, the module looks like this:
When I close the project and open up a 2nd time, the module looks like this:
(With the inability to run because Run/Debug says 'No Android facet found in the module')
I can get back to my original state by doing File->Open and reselecting the pom.xml file. I make sure to hit no on the first pop-up:
I blanked out my build.gradle file like so:
buildscript {
repositories {
}
dependencies {
}
}
repositories {
}
dependencies {
}
Extra Notes:
Exported from eclipse ADT for a build.gradle file. Android Studio was missing all External Libraries that were Maven
Dependencies.
Started my own build.gradle file to indlude dependencies but I don't want to maintain two separate files (build.gradle & pom.xml).
Deleted the build.gradle file and anything gradle related in the android project folder before reopening but that did nothing.
Developing on Linux OS Android Studio version 0.4.2
I don't like to answer my own questions but I thought a work around might help others in this case.
What I noticed is that Android Studio fights between gradle and maven and chooses gradle if you have a gradlefile for the project as well as maven.
Work Around
Open Module Settings
Remove all modules. Select the module and hit the minus key to
delete.
Click yes on the prompt.
Open up Maven Projects and click the plus key
Browse to your pom file and hit open.

Resources