.ERROR: Gradle DSL method not found: 'google()' - android-gradle-plugin

after working on an old source code ...i upgraded everything from sdk to gradle but when i rebuilt the project i got ERROR: Gradle DSL method not found: 'google()' please help
dependencies {
classpath 'com.android.tools.build:gradle:3.4.0'
classpath 'com.google.gms:google-services:4.2.0'
}

Related

`kotlinx.serialization` plugin in `build.gradle.kts` isn't caught up by the Idea IDE

I'm currently trying to set up kotlin serialization for my project, and keep getting this error from the Idea IDE on usage of #Serializable decorator
kotlinx.serialization compiler plugin is not applied to the module, so this annotation would not be processed. Make sure that you've setup your buildscript correctly and re-import project.
My build.gradle.kts contains that, which is just right according to the setup guide in their repo:
plugins {
kotlin("jvm") version "1.6.10"
kotlin("plugin.serialization") version "1.6.10"
java
}
dependencies {
implementation(kotlin("stdlib"))
testImplementation("org.junit.jupiter:junit-jupiter-api:5.6.0")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")
implementation(kotlin("script-runtime"))
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.3.2")
}
It does compile and run as intended, the example in the repo i linked above works just right. But IntelliJ Idea still keeps showing me this error.
I've tried reloading gradle project, invalidating index, and restarting my IDE few times.

Importing a source dependency with Gradle (Kotlin DSL)

I want to import version 1.0.0 of this project https://github.com/whichdigital/ksv
as a source dependency in a Kotlin project using Gradle 6.3 with Kotlin DSL.
As the page tells me I added this into the settings.gradle.kts of my project
sourceControl {
gitRepository(java.net.URI.create("https://github.com/whichdigital/ksv.git")) {
producesModule("uk.co.whichdigital:ksv")
}
}
and using this dependency in my build.gradle.kts file:
implementation("uk.co.whichdigital:ksv:1.0.0")
trying to import tagged version/release 1.0.0 of the KSV repo. But building my project (importing the KSV repo) fails with following expection:
TaskDependencyResolveException: Could not determine the dependencies of task ':bootJar'.
...
Caused by: DefaultLenientConfiguration$ArtifactResolveException: Could not resolve all task dependencies for configuration ':runtimeClasspath'.
....
Caused by: ModuleVersionResolveException: Git repository at https://github.com/whichdigital/ksv.git did not contain a project publishing the specified dependency.
Required by:
project :
I'm actually also the person who wrote/published the KSV-repository, so if there's some configuration that I missed, I can add it in the imported or importing project.
"uk.co.whichdigital:ksv:1.0.0" group id is wrong.
Can you please try
sourceControl {
gitRepository(java.net.URI.create("https://github.com/whichdigital/ksv.git")) {
producesModule("uk.co.whichdigital.ksv:ksv")
}
}
implementation("uk.co.whichdigital.ksv:ksv:1.0.0")

Intellij Plugin Development - Gradle does not find dependency of IntelliJ

I am currently developing a plugin for IntelliJ and trying to use another built-in IntelliJ Plugin as dependency (git4idea). As described in the IntelliJ Plugin Development documentation, I added the required JARs to my class Path in Project Structure:
Project Structure Dialog Screenshot
I also added <depends>Git4Idea</depends> to my plugin.xml file.
IntelliJ finds these jars now and Code Completion works well, no errors found...
But when I try to build the Plugin with gradle I get ClassNotFound errors or errors like this:
TkGitflowBaseImpl.java:15: error: package git4idea.commands does not exist
import git4idea.commands.Git;
^
Obviously, Gradle does not find these jars. Since they are part of the IntelliJ installation, I can't just add them to a lib folder and add them as local jars in the build.gradle file. As Gradle JVM, I chose the exact same JVM I chose as JVM behind the IDEA Platform SDK, so the jars should be available to Gradle.
Do you know how I can help Gradle find these jars or add them as "provided" dependencies without adding them to a lib folder?
I am using IntelliJ IDEA 2017.2.5 and Gradle 4.2.1
After reading through the documentation of the IntelliJ Gradle Plugin (https://github.com/JetBrains/gradle-intellij-plugin), I saw that that a "=" was missing in the build.gradle file like:
intellij {
version '2017.2.5'
pluginName 'pluginname'
plugins = ['Git4Idea']
}
instead of
intellij {
version '2017.2.5'
pluginName 'pluginname'
plugins ['Git4Idea']
}
https://plugins.jetbrains.com/docs/intellij/plugin-dependencies.html#optional-plugin-dependencies
build.gradle
intellij {
version = '2021.2'
plugins = ['Git4Idea']
}
src\main\resources\META-INF\plugin.xml
<depends>Git4Idea</depends>

Gradle build settings in IntelliJ

What can I do to make the following Gradle project build succesfully?
I've build a new project. settings.gradle is:
rootProject.name = 'myproject'
build.gradle is:
group 'mygroup'
version '1.0-SNAPSHOT'
apply plugin: 'groovy'
apply plugin: 'java'
apply plugin: 'idea'
sourceCompatibility = 1.5
repositories {
mavenLocal()
mavenCentral()
maven { url "https://plugins.gradle.org/m2/" }
maven { url "https://mvnrepository.com/artifact/org.apache.commons/commons-lang3" }
}
dependencies {
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.6'
compile 'org.codehaus.groovy:groovy-all:2.3.11'
testCompile group: 'junit', name: 'junit', version: '4.11'
}
If I use "Refresh all gradle projects" in the Gradle Tool Window, the Event Log says:
Unindexed remote maven repositories found. [Disable...]
The following repositories used in your gradle projects were not indexed yet:
https://plugins.gradle.org/m2
https://mvnrepository.com/artifact/org.apache.commons/commons-lang3
Project Structure --> Problems tells me:
Library Gradle: org.apache.commons:commons-lang3:3.6 has broken
classes path:   /home/myhome/git/myproject/Could not resolve
org.apache.commons:commons-lang3:3.6.
Does anybody know a good instruction website for building gradle projects (other than Getting started with Gradle)? I've also re-setup the project based on these instructions, but I cannot resolve any dependencies either. (auto-import enabled and using a Gradle wrapper)
Do you have maven installed?
With regards to mavenLocal() Gradle goes and reads ~/.m2/settings.xml to find the info about where is your repo situated, when it can't find any info it is going to assume it's '~/.m2/repository'
Please update the question with the IntelliJ version you are using as versions from 2015, 2016 wasn't that good with Gradle integration yet, if you are using an outdated version, I recommend downloading latest and trying again.
You can use some kind of a workaround for this, in your build.gradle apply plugin: 'idea' and then on the command line do gradle cleanIdea idea - this will delete and recreate your idea files .iws .ipr .iml and recrete the classhpaths and your project should refresh in IntelliJ and work just fine
The problem disappeared after:
upgrading from IntelliJ 2016.3 to 2017.2
setting up another project from scratch
being asked to deactivate "Gradle offline mode" - and answering yes.
Obviously the problem was the "Gradle offline mode" which can be directly deactivated as described in this answer.

IntelliJ, Android and Gradle

I am trying to get my existing Android Project working with gradle and IntelliJ 12.
Previously I had it working with maven but that didn't seem to be so flexible as gradle, and from what I think I got to know is that I need less subfolders.
My Android project is divided into a clean java library (:core) and the actual Application (:android). These two projects are both in my main project folder.
~-+MainProject
|--+core
| L--build.gradle
|--+android
| L--build.gradle
|--build.gradle
L--settings.gradle
I think the ideal solution to get gradle work with this is to treat the (:core) and (:android) project as nested projects, meaning I can simply be with my cmd in MainProject source folder to start the gradle tasks.
However I came up with different problems:
Gradle dependencies are only included in the core project
that means neither in the instrumentatetionTest nor in the main project files are any
directories correctly set as source / test directories
IntelliJ doesn't resolve any classes that I added as dependencies in gradle (AndroidSDK, junit, mockito, those from the :core project)
tried to use the plugin 'idea' but either I used it wrong or it didn't solve the problem
I get duplicate dependency Error for building the APK
must have something to do with junit:4.11 and mockito-core:1.9.5 that I added
what I tried:
deleting the dependencys -> build fails cause some classes of course could'nt be resolved
changing to junit:4.5+ as suggesed in some other thread -> no change at all
Here are the *.gradle configuartions
MainProject:
-- settings.gradle
include ':core', ':android'
-- build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
}
}
subprojects {
repositories {
mavenLocal()
maven { url "http://repo.maven.apache.org/maven2" }
}
}
:core
-- build.gradle
apply plugin: 'java'
dependencies {
testCompile 'junit:junit:4.11'
testCompile 'org.mockito:mockito-core:1.9.5'
}
:android
apply plugin: 'android'
repositories {
mavenCentral()
}
dependencies {
compile project(":core")
compile 'com.google.android:android:4.1.1.4'
instrumentTestCompile 'junit:junit:4.11'
instrumentTestCompile 'org.mockito:mockito-core:1.9.5'
instrumentTestCompile 'com.google.dexmaker:dexmaker:1.0'
instrumentTestCompile 'com.google.dexmaker:dexmaker-mockito:1.0'
instrumentTestCompile 'com.jayway.android.robotium:robotium-solo:3.6'
}
/* ... androidSettings
I hope someone could help me with that
MFG Dornathal
Alright, so you've got the right idea, but there are a few changes you still need.
Your root build.gradle file should be as follows:
subprojects {
repositories {
mavenCentral()
}
}
You only need to include mavenLocal() if you are using a locally installed repo. Most people don't, and nothing in your project indicates that you need one.
mavenCentral() can be used to replace to maven URL you were using.
We only need to modify the buildscript for the android project, so we should localize that to the android project's build.gradle.
Your settings.gradle and your build.gradle for the core project are good.
Your build.gradle for the android project however, needs some changes:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
}
}
apply plugin: 'android'
dependencies {
compile project(":core")
instrumentTestCompile 'com.jayway.android.robotium:robotium-solo:3.6'
}
By including the android plugin, we link directly to the installed SDK. This means we no longer need to include the android dependency: compile 'com.google.android:android:4.1.1.4'.
We don't need to include junit. It's provided by the SDK, so we'll just use that. One thing to note is that the SDK only includes JUnit 3.
We don't need to include mockito and dexmaker unless we actually use it for the android tests. If it's only being used for the tests on the java library, we don't need it here.
To answer your questions:
I'm not sure what you're asking here. It might help if you should your project structure including the directories in which you have files and such.
Your hunch is correct. Hamcrest, which provides matchers for tests, made a breaking change to their API between versions 1.1 and 1.3. JUnit 4.11 has a dependency on Hamcrest 1.3. Mockito 1.9.5 however, depends on Hamcrest 1.1. So when both are included, the 1.3 overrides the 1.1 & Mockito no longer works. Reverting to JUnit 4.5 is also a problem. Junit 4.5 includes the Hamcrest 1.1 jar as a file rather than as a dependency in the POM. So this will cause issues when we have 2 versions of the same file. JUnit 4.10 is the way you want to go here. This has the dependency on Hamcrest 1.1 and includes it in the POM instead of as a file. Win win! I've had issues with this too, and the best way for me to figure it out was to just look at the POM files on Maven Central and see what they tell me.
One final note. Intellij 12 cannot handle Gradle Multi-project builds. You need to switch to Android Studio or Intellij 13 for that.