Node Build fail after upgrade to Gradle 7.3 - node.js

We have upgrade gradle from 4.8 to 7.3 after that nodeSetup build gets fail with below error.
Could not find method layout() for arguments [pattern, com.moowork.gradle.node.task.SetupTask$_addRepository_closure5$_closure7#25995910] on object of type org.gradle.api.internal.artifacts.repositories.DefaultIvyArtifactRepository.
Below are code snippet of build.gradle.
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "com.moowork.gradle:gradle-node-plugin:1.3.1"
classpath "io.spring.gradle:dependency-management-plugin:1.0.11.RELEASE"
}
}
apply plugin: "com.moowork.node"
apply plugin: "io.spring.dependency-management"
node {
version = "16.13.12"
npmVersion = "6.12.0"
download = true
nodeModulesDir = file("/XXX")
}

Cause:
There is a breaking change in gradle 6.8 which is you can checkout here:
https://docs.gradle.org/current/userguide/upgrading_version_6.html#configuring_the_layout_of_an_ivy_repository
"The 'layout' method taking a configuration block has been removed and
is replaced by 'patternLayout'
Your plugin "com.moowork.gradle:gradle-node-plugin:1.3.1" is using that method which not upgraded in this library.
Solution:
You can use this gradle-node-plugin instead of "com.moowork.gradle:gradle-node-plugin:1.3.1"
Installation:
https://github.com/node-gradle/gradle-node-plugin/blob/master/docs/installation.md
Installing the node-related plugins can be done in multiple ways. The easiest is to use the plugins-closure in your build.gradle file:
plugins {
id "com.github.node-gradle.node" version "3.1.1"
}
You can also install the plugins by using the traditional Gradle way:
buildscript {
repositories {
gradlePluginPortal()
}
dependencies {
classpath "com.github.node-gradle:gradle-node-plugin:3.1.1"
}
}
apply plugin: 'com.github.node-gradle.node'

Related

This version (1.1.1) of the Compose Compiler requires Kotlin version 1.6.10 but you appear to be using Kotlin version 1.5.31

I'm using the latest Android Studio and I'm able to build and run my app fine with compose_version set to 1.0.5. However, I'd like to use the latest stable compose version 1.1.1.
I try to simply update the project build.gradle so it contains the following pointing to the desired compose version and the corresponding compatible kotlin version. These values are referenced in the app's build.gradle.
buildscript {
ext {
compose_version = '1.1.1'
kotlin_version = '1.6.10'
}
And in Android Studio, I go to Tools > Kotlin > Configure Kotlin Plugin Updates and download the latest Kotlin plugin (Early Access).
If I open Tools > Kotlin > Kotlin REPL, I see Welcome to Kotlin version 1.7.0-RC2-release-258 (JRE 11.0.12+0-b1504.28-7817840).
Now, I try to Rebuild Project.
I get the error:
This version (1.1.1) of the Compose Compiler requires Kotlin version 1.6.10 but you appear to be using Kotlin version 1.5.31 which is not known to be compatible. Please fix your configuration (or suppressKotlinVersionCompatibilityCheck but don't say I didn't warn you!).
I don't wish to suppressKotlinVersionCompatibilityCheck given the warning, but I even tried that option and got other build errors.
Why is Kotlin version 1.5.31 being used? Shouldn't updating the Kotlin plugin have gotten Android Studio to switch to a more recent Kotlin version (as suggested by the Kotlin REPL message)? How can I make it such that Kotlin 1.6.10 is used and I stop getting the error?
Got the same error when using Compose 1.1.1. and Kotlin 1.7.0.
Task :app:compileDebugKotlin FAILED
e: This version (1.1.1) of the Compose Compiler requires
Kotlin version 1.6.10 but you appear to be using Kotlin version 1.7.0
which is not known to be compatible. Please fix your configuration (or suppressKotlinVersionCompatibilityCheck but don't say I didn't warn you!).
Changed the below block in my build.gradle (app module)
composeOptions {
kotlinCompilerExtensionVersion 1.2.0
}
This is my plugins block in build.gradle (project):
plugins {
id 'com.android.application' version '7.2.1' apply false
id 'com.android.library' version '7.2.1' apply false
id 'org.jetbrains.kotlin.android' version '1.6.21' apply false
id 'org.jetbrains.kotlin.jvm' version '1.7.0' apply false
}
This Android developers page helped with picking the compatible versions :-
Compose to Kotlin Compatibility Map
Don't forget to sync and rebuild.
Compose uses the kotlin compiler defined in your buildscript block:
buildscript {
ext.kotlin_version = '1.6.10'
//....
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
If you are using the plugins block in settings.gradle or build.gradle:
pluginManagement {
plugins {
id 'org.jetbrains.kotlin.android' version '1.6.10'
}
}
Using this help me.
build.gradle (:app)
composeOptions {
kotlinCompilerExtensionVersion = "1.2.0-beta03"
}
There are 3 things you need to ensure are in sync(compatible with the other) for kotlin to work properly.
1)compose_ui_version='1.2.1' of buildscript in build.gradle(project)
2)plugin 'org.jetbrains.kotlin.android' version '1.7.10' in build.gradle(project)
3)kotlinCompilerExtensionVersion '1.3.1' in composeOptions in build.gradle(app)
To get the latest version of compose compiler and its corresponding kotlin version check here.
for me what I had to edit is to locate build graddle(Project):
first load compose_version to see the latest stable compose_version.
buildscript {
ext {
//2. change here to the latest stable (compose_version) that you got in step 1
compose_version = '1.3.0'
}
repositories {
google()
mavenCentral()
}
dependencies {
//when you run you app, The next error will tell you the version of Kotlin that the latest compose_version needs, edit as below to the version required in the error
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.10'
}
buildscript {
dependencies {
classpath 'com.android.tools.build:gradle:7.1.3'
}
}
plugins {
id 'org.jetbrains.kotlin.android' version '1.6.10' apply false
}
and build.gradle(Module)
composeOptions {
kotlinCompilerExtensionVersion '1.1.1'
}
Go to your project level build.gradle file
There in the plugin section below mentioned 2 libraries has to be in the same version to remove this error:
{
...
id 'org.jetbrains.kotlin.android' version '1.6.10' apply false
id 'org.jetbrains.kotlin.jvm' version '1.6.10' apply false
}
If required, change:
compileSdk 33
&
targetSdk to 33
. (inside app level build.gradle file).
Now sync the project & reload the priview. It will work fine.

Could not execute build using Gradle distribution

I have the following error: "Could not execute build using Gradle distribution 'https://services.gradle.org/distributions/gradle-4.4-all.zip'."
It only occurs if I have this in my gradle file:
"classpath 'com.android.tools.build:gradle:3.1.2'"
if I switch it back to:
"classpath 'com.android.tools.build:gradle:3.0.1'"
everything works again. This started after I updated gradle and android studio today.
I have tried just about every solution in this question but nothing helped:
Gradle error: could not execute build using gradle distribution
from above:
-I tried deleting the .gradle in the user folder, and restarting android studio (I also restarted my computer after several other attempts)
-gradle build is successful, I tried invalidate caches and restart. (I tried this before deleting the .gradle, would it make a difference doing it again?)
-I tried setting gradle home to several other paths but nothing helped. If I go to my android studio folder/gradle theres a gradle-4.4 folder but not any of the previous versions that work. .gradle has both 4.4 and 4.1 though.
I tried the following gradle home paths:
C:/Program Files/Android/Android Studio/gradle/gradle-4.4
C:/Users/Joseph/.gradle/wrapper/dists/gradle-4.4-all/9br9xq1tocpiv8o6njlyu5op1/gradle-4.4
/usr/local/opt/gradle/libexec/
and path/to/gradle/libexec/
as well as the default wrapper. (which I have it set to now)
It's possible my jdk/jre are set wrong but they have been working up until now.
my project gradle:
buildscript {
repositories {
mavenLocal()
mavenCentral()
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
jcenter()
google()
}
dependencies {
classpath 'de.richsource.gradle.plugins:gwt-gradle-plugin:0.6'
classpath 'com.android.tools.build:gradle:3.1.2'
classpath 'com.mobidevelop.robovm:robovm-gradle-plugin:2.3.1'
}
}
allprojects {
apply plugin: "eclipse"
apply plugin: "idea"
version = '1.0'
ext {
appName = "IdlePortalDefense"
gdxVersion = '1.9.6'
roboVMVersion = '2.3.1'
box2DLightsVersion = '1.4'
ashleyVersion = '1.7.0'
aiVersion = '1.8.0'
}
repositories {
mavenLocal()
mavenCentral()
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
maven { url "https://oss.sonatype.org/content/repositories/releases/" }
google()
}
}
project(":desktop") {
apply plugin: "java"
dependencies {
implementation project(":core")
implementation "com.badlogicgames.gdx:gdx-backend-lwjgl:$gdxVersion"
implementation "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
implementation "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-desktop"
implementation "com.badlogicgames.gdx:gdx-tools:$gdxVersion"
}
}
project(":android") {
apply plugin: "android"
configurations { natives }
dependencies {
implementation project(":core")
implementation "com.badlogicgames.gdx:gdx-backend-android:$gdxVersion"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi-v7a"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-arm64-v8a"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86_64"
implementation "com.badlogicgames.gdx:gdx-box2d:$gdxVersion"
natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-armeabi"
natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-armeabi-v7a"
natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-arm64-v8a"
natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-x86"
natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-x86_64"
}
}
project(":ios") {
apply plugin: "java"
apply plugin: "robovm"
dependencies {
implementation project(":core")
implementation "com.mobidevelop.robovm:robovm-rt:$roboVMVersion"
implementation "com.mobidevelop.robovm:robovm-cocoatouch:$roboVMVersion"
implementation "com.badlogicgames.gdx:gdx-backend-robovm:$gdxVersion"
implementation "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-ios"
implementation "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-ios"
}
}
project(":core") {
apply plugin: "java"
dependencies {
implementation "com.badlogicgames.gdx:gdx:$gdxVersion"
implementation "com.badlogicgames.gdx:gdx-box2d:$gdxVersion"
}
}
tasks.eclipse.doLast {
delete ".project"
}
my graddle wrapper:
#Wed Apr 25 00:05:44 EDT 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
Thanks FF7Squirrelman for sharing the problem the solution.
For me I have also fixed the problem by updating gradle distribution from gradle-4.4-all.zip to gradle-4.7-all.zip
The problem I got is I can "Build APK" and run it on my mobile via Android Studio. However, when I generate signed APK, i got the error same as above.
Looking around the web, it sounds like there is bug on gradle-4.4 which causes the issue and I have proceed below to solve the issue as F7Squirrelman suggested:
updating gradle-wrapper.properties:
distributionUrl=https://services.gradle.org/distributions/gradle-4.7-all.zip
Go to File -> Setting -> Build,Execution and Deployment -> Compiler
Uncheck the box: Configure on Demand
It will allow the project built in gradle 4.7 and finally it solves the issue.

including dependency in gradle

I want to include 'org.scribe:scribe:1.3.2' dependency into my gradle project, I have added the following line to my build.gradle file
apply plugin: 'groovy'
repositories {
mavenCentral()
}
dependencies {
runtime 'org.scribe:scribe:1.3.2'
compile 'org.codehaus.groovy:groovy-all:2.2.0'
}
task fbTask << {
MyTask mT = new MyTask()
mT.loginUsingFacebook();
}
Now inside MyTask.groovy
import org.scribe.model.Token
public void loginUsingFacebook() {
Token accessToken = //some code
}
It didn't find the import, which shows that the scribe dependency we specified in build.gradle didn't worked.
So, how to import this scribe dependency into the application , so that i can use it in my Task class.
There are some misconceptions here:
Dependencies declared in the project.dependencies block are for code produced by the build, not for code used by the build.
Gradle tasks cannot be instantiated with new.
How to add a dependency used by the build itself (typically by a build script, task class, or plugin class) depends on where you put the corresponding code. In the simplest case, the task class is declared right in the build script, and its dependencies go into a buildscript block:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath "org.scribe:scribe:1.3.2"
}
}
To learn more about these topics, check out the Gradle User Guide, and the samples in the full Gradle distribution.
If you want to add something to classpath of buildscript(build.gradle) and not the project source, then add it to buildScript closure.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'org.scribe:scribe:1.3.2'
}
}
Reference : In Gradle documentation's Organizing Build Logic chapter, see the section External dependencies for the build script

Add maven dependency to Android Studio gradle

Just trying Android Studio & Gradle and I want to add Roboguice to my Project, this is my build.gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.8.+'
}
}
allprojects {
repositories {
mavenCentral()
}
}
dependencies {
compile 'org.roboguice:roboguice:2.0'
}
gives me
Gradle 'TestApp' project refresh failed:
Build script error, unsupported Gradle DSL method found: 'compile()'!
I tried to move the line
compile 'org.roboguice:roboguice:2.0'
within the dependencies in buildscript but that also failed.
How is this done correctly?
dependencies {
compile 'org.roboguice:roboguice:2.0'
}
Move this part from build.gradle in root (top level build file) to build.gradle in your module

Errors with gradle on Android Studio 0.4.6

Hello StackOverflow,
I have recently updated my Android Studio to the latest version (0.4.6), and I am encountering weird problems with it. When first creating my project, I got this error:
So I obviously went to my SDK Manager and updated my Build Tools to version 19.0.2. However, I still got this error message. I took a look into my build.gradle file and saw that I am missing the android paragraph, So I changed it from this:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.8.+'
}
}
allprojects {
repositories {
mavenCentral()
}
}
To this:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.8.+'
}
}
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion '19.0.2'
//Other Configuration
}
allprojects {
repositories {
mavenCentral()
}
}
But now I am getting this error message when trying to build (and the older Build Tools error):
I'm not sure what to do now.. How can I solve this?
As suggested by Scott keep your Root level build.gradle file like this
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.8.+'
}
}
allprojects {
repositories {
mavenCentral()
}
}
Content of this file will be included in each module level build.gradle file at the type of Gradle sync or compilation.
Check all build.gradle files inside your modules. They all should look similar to this
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion '19.0.2'
//Other Configuration
}
dependencies{
// Your all module dependencies here
}
Undo the changes you made to the top-level build file, and make those changes to the build files in your individual modules. In particular, putting an apply plugin: 'android' statement or android block in your top-level build file in that manner won't work. The error message you're seeing is happening because the build system is trying to build an Android app out of the root directory of your project, but none of the source files for such a project are there.

Resources