'dependencies' cannot be applied to '(groovy.lang.Closure) - groovy

I am using Groovy/Gradle with Cucumber framework. following are the versions
Groovy Version: 2.4.4
------------------------------------------------------------
Gradle 2.5
------------------------------------------------------------
Build time: 2015-07-08 07:38:37 UTC
Build number: none
Revision: 093765bccd3ee722ed5310583e5ed140688a8c2b
Groovy: 2.3.10
Ant: Apache Ant(TM) version 1.9.3 compiled on December 23 2013
JVM: 1.7.0_17 (Oracle Corporation 23.7-b01)
OS: Windows 8 6.2 amd64
I am getting this error when I try to run following
$ gradle clean idea
FAILURE: Build failed with an exception.
* Where:
Build file 'C:\Documents and Settings\Sudheerah\Documents\Sudheera\KBase\APDM\APIAutomation\build.gradle' line: 76
* What went wrong:
A problem occurred evaluating root project 'APIAutomation'.
> Could not find method groovy() for arguments [org.codehaus.groovy:groovy-all:2.4.4] on root project 'APIAutomation'.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 35.237 secs
Below is the build.gradle file error line.
Stacktrace
Caused by: org.gradle.api.internal.MissingMethodException: Could not find method groovy() for arguments [org.codehaus.groovy:groovy-all:2.4.4] on root project 'APIAutomation'.
at org.gradle.api.internal.AbstractDynamicObject.methodMissingException(AbstractDynamicObject.java:68)

Assuming you've applied the groovy plugin, you need to change your groovy dependency to a compile dependency.
The groovy dependency is the old way of setting up the groovy plugin

Related

Android Studio: Failed to apply plugin 'com.android.internal.version-check'

I have installed below Android version and used some of the latest SDK versions as per the below image and also used the latest gradle version same as shown in the below image and I have also tried downgrading and upgrading multiple grade versions but still getting the below error can anyone help me on that? or have you faced this type of specific error?
Android Studio Electric Eel | 2022.1.1 Patch 1
Build #AI-221.6008.13.2211.9514443, built on January 21, 2023
Runtime version: 11.0.15+0-b2043.56-9505619 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Windows 10 10.0
GC: G1 Young Generation, G1 Old Generation
Memory: 1280M
Cores: 16
Registry:
external.system.auto.import.disabled=true
ide.text.editor.with.preview.show.floating.toolbar=false
Non-Bundled Plugins:
wu.seal.tool.jsontokotlin (3.7.4)
Dart (221.6096)
com.developerphil.adbidea (1.6.8)
io.flutter (72.1.2)
ERROR FACING:
* What went wrong:
An exception occurred applying plugin request [id: 'com.android.application']
> Failed to apply plugin 'com.android.internal.version-check'.
> Could not create plugin of type 'VersionCheckPlugin'.
> com/google/common/base/Splitter
* What went wrong:
An exception occurred applying plugin request [id: 'com.android.application']
> Failed to apply plugin 'com.android.internal.version-check'.
> Could not create plugin of type 'VersionCheckPlugin'.
> Could not initialize class com.android.build.gradle.internal.plugins.VersionCheckPlugin
* Exception is:
org.gradle.api.plugins.InvalidPluginException: An exception occurred applying plugin request [id: 'com.android.application']
at org.gradle.plugin.use.internal.DefaultPluginRequestApplicator.exceptionOccurred(DefaultPluginRequestApplicator.java:223)
at org.gradle.plugin.use.internal.DefaultPluginRequestApplicator.applyPlugin(DefaultPluginRequestApplicator.java:205)
at org.gradle.plugin.use.internal.DefaultPluginRequestApplicator.applyPlugin(DefaultPluginRequestApplicator.java:147)
at org.gradle.plugin.use.internal.DefaultPluginRequestApplicator.access$200(DefaultPluginRequestApplicator.java:61)
at org.gradle.plugin.use.internal.DefaultPluginRequestApplicator$1$1.lambda$add$1(DefaultPluginRequestApplicator.java:120)
at org.gradle.plugin.use.internal.DefaultPluginRequestApplicator.lambda$applyPlugins$0(DefaultPluginRequestApplicator.java:143)
* Get more help at https://help.gradle.org
CONFIGURE FAILED in 421ms

Gradle Groovy compilation cannot find javafx classes in tests

I have the following Groovy test (not the real one, mind you) in a Gradle project (under src/test/groovy):
import javafx.scene.paint.Color
import org.junit.Test
class MyTest {
#Test
void test1() {
assert Color.AQUAMARINE != Color.BLUE
}
}
The build file is as simple as it gets and declares that I use Java 8 (so JavaFX is in the classpath, always):
apply plugin: 'groovy'
compileJava {
sourceCompatibility = 1.8
targetCompatibility = 1.8
}
...
It also has a test dependency on Groovy:
testCompile group: 'org.codehaus.groovy', name: 'groovy-all', version: '2.4.4'
Everything works fine, except when I refer to some JavaFX class in the Groovy test.
It fails with this error:
MyTest.groovy: 3: unable to resolve class javafx.scene.paint.Color
# line 3, column 1.
import javafx.scene.paint.Color
^
The Java code compiles fine and I can run my JavaFX application. Only the Groovy tests seem to not be able to see JavaFX.
I've already tried changing the compileJava block to compileGroovy, compileTestGroovy, also together with the compileJava block, so that the Groovy compiler sees JavaFX 8, but nothing helped.
How can I fix this?
Gradle version:
------------------------------------------------------------
Gradle 2.2
------------------------------------------------------------
Build time: 2014-11-10 13:31:44 UTC
Build number: none
Revision: aab8521f1fd9a3484cac18123a72bcfdeb7006ec
Groovy: 2.3.6
Ant: Apache Ant(TM) version 1.9.3 compiled on December 23 2013
JVM: 1.8.0_60 (Oracle Corporation 25.60-b23)
OS: Linux 3.16.0-38-generic amd64
Changed the Gradle version to 2.7 (latest as of today) and it all works.
If you have the same problem, just use Gradle's wrapper and set the Gradle version to the latest version (they move fast, so bugs will exist, but also get fixed quickly).
gradle wrapper --gradle-version 2.7

Gradle Build sample fails with "You must assign a Groovy library to the 'groovy' configuration."

I have a build.gradle file (from the custom plugin example in the manual) that reads:
apply plugin: 'groovy'
dependencies {
compile gradleApi()
compile localGroovy()
}
But when I run I get:
$ gradle build
:compileJava UP-TO-DATE
:compileGroovy
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileGroovy'.
> You must assign a Groovy library to the 'groovy' configuration.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Any idea what I am missing?
Ensure you have both:
apply plugin: 'groovy'
and use the groovy keyword in the dependencies section (rather than using the compile keyword):
dependencies {
groovy 'org.codehaus.groovy:groovy-all:2.0.8
}
All credit to this blog.
Short answer, upgrade to a newer version.
The above problem (and a few more) where happening on v1.0.8, upgrading to v1.6 and its all works properly

Checking Groovy version Gradle is using

I am running gradle and have previously been running groovy 1.76. I have now updated to groovy on my local machine (groovy_home points to groovy 2.1.2 etc).
$ groovy -version
Groovy Version: 2.1.2 JVM: 1.7.0_17 Vendor: Oracle Corporation OS: Linux
However, when I am running gradle commands (gradle test, classes, etc) I believe it is not building against groovy 2.1.2 but is actually still building against 1.76. (The reason I believe this, is that when I execute the classes I keep getting this error Upgrading Groovy 1.7 - 2.1 Incompatability, which is related to changes made post 1.76)
Is there a way to confirm which version of groovy my gradle install is building against?
Also, can anyone confirm where I should be configuring the groovy version for gradle?
While trying to check the groovy version during gradle runtime, I found you can also print the Groovy version:
task version {
doLast {
println "Gradle version: " + project.getGradle().getGradleVersion()
println "Groovy version: " + GroovySystem.getVersion()
}
}
As examples:
$ ~/usr/gradle-1.8/bin/gradle -q version
Gradle version: 1.8
Groovy version: 1.8.6
$ ~/usr/gradle-2.1/bin/gradle -q version
Gradle version: 2.1
Groovy version: 2.3.6
Note.- GroovySystem.getVersion() is available since Groovy 1.6.9
Which Groovy library you are building against (and which Groovy compiler you are using) is determined by which Groovy library resides on the compile (or, in earlier Gradle versions, groovy) configuration. Typically a Groovy dependency is configured explicitly, but it may also be pulled in by transitive dependency management. (In case of a version conflict, the higher version wins by default. Which Groovy version(s) you have installed on your machine is irrelevant.) gradle dependencyInsight --configuration compile --dependency groovy should provide the answer.
Here is how a Groovy dependency is typically configured:
apply plugin: "groovy"
repositories {
mavenCentral() // or some other repository containing a Groovy library
}
dependencies {
// in Gradle 1.4 or earlier, replace 'compile' with 'groovy'
compile "org.codehaus.groovy:groovy-all:2.1.2"
}
in windows you can check it using: gradlew --v
------------------------------------------------------------
Gradle 6.2
------------------------------------------------------------
Build time: 2020-02-17 08:32:01 UTC
Revision: 61d3320259a1a0d31519bf208eb13741679a742f
Kotlin: 1.3.61
Groovy: 2.5.8
Ant: Apache Ant(TM) version 1.10.7 compiled on September 1 2019
JVM: 15.0.2 (Oracle Corporation 15.0.2+7-27)
on linux the command will be : gradle --v
I'm using osx
gradle --v
------------------------------------------------------------
Gradle 7.5.1
------------------------------------------------------------
Build time: 2022-08-05 21:17:56 UTC
Revision: d1daa0cbf1a0103000b71484e1dbfe096e095918
Kotlin: 1.6.21
Groovy: 3.0.10
Ant: Apache Ant(TM) version 1.10.11 compiled on July 10 2021
JVM: 17.0.4.1 (Homebrew 17.0.4.1+1)
OS: Mac OS X 12.4 x86_64

Geb + Spock + groovy setup

So I've been attempting to get these tools running together, but I can't seem to get things setup properly. Each time I am presented with the following error:
The project was not built since its build path is incomplete. Cannot find the class file for org.spockframework.mock.MockController. Fix the build path then try building this project.
I've created this gist. When I run gradle chrome test I get the following output:
gradle chrome test
:compileJava UP-TO-DATE
:compileGroovy UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:compileTestJava UP-TO-DATE
:compileTestGroovy FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileTestGroovy'.
> org/spockframework/mock/MockController
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
I'm using gradle 1.3, geb 0.7.2 and spock 0.7-groovy-2.0. I've also tried updating geb to utilize 0.9.0-RC-1. The gist above should have everything needed to see this same error.
This is what you get when you run Spock 0.7 with Geb versions lower than 0.9.0-RC-1 (which aren't compatible with Spock 0.7). Double check your setup and perform a clean build.
I was running into the same problem. It turns out you need to use the groovy 1.8 version because the Geb/Spock integration jars haven't been upgraded to groovy 2.0 yet. The following setup worked for me:
dependencies {
def seleniumVersion = "2.42.2"
def phantomJsVersion = '1.1.0'
def cargoVersion = '1.4.9'
// selenium drivers
compile "org.seleniumhq.selenium:selenium-ie-driver:$seleniumVersion"
compile "org.seleniumhq.selenium:selenium-chrome-driver:$seleniumVersion"
compile "org.seleniumhq.selenium:selenium-firefox-driver:$seleniumVersion"
compile "org.seleniumhq.selenium:selenium-support:$seleniumVersion"
compile("com.github.detro.ghostdriver:phantomjsdriver:$phantomJsVersion") {
transitive = false
}
// geb
compile 'org.codehaus.geb:geb-core:0.7.2'
compile 'org.codehaus.geb:geb-spock:0.7.2'
// spock
compile 'org.spockframework:spock-core:0.6-groovy-1.8'
compile 'junit:junit:4.8.2'
compile 'org.slf4j:slf4j-log4j12:1.7.6#jar'
compile 'org.slf4j:slf4j-api:1.7.6#jar'
}
I posted my full script that includes cargo integration on my blog: http://www.openscope.net/2015/02/21/how-to-configure-gebspock-with-gradle/

Resources