Gradle compileGroovy java.lang.ExceptionInInitializerError - maven

Here is the github repo: https://github.com/entrpn/gradle_plugin. You will need to manually create a folder "repo" at the root of the project since git doesn't add empty directories. That is where the generated files are supposed to go when running:
./gradlew uploadArchives
I am trying to write a simple gradle plugin following this tutorial https://afterecho.uk/blog/create-a-standalone-gradle-plugin-for-android-a-step-by-step-guide.html and when I get to the part where I am trying to create the local maven repo, I am not able to.
Problem: I am using the gradle wrapper command line:
./gradlew uploadArchives
and I receive the above error. Anyone know what I am doing wrong. Here is the log output:
Executing org.gradle.api.internal.tasks.compile.ApiGroovyCompiler in worker daemon.
16:20:23.624 [INFO] [org.gradle.workers.internal.WorkerDaemonServer] Exception executing org.gradle.api.internal.tasks.compile.ApiGroovyCompiler in worker daemon: java.lang.ExceptionInInitializerError.
16:20:23.636 [DEBUG] [org.gradle.internal.operations.DefaultBuildOperationWorkerRegistry] Worker root.2.3 completed (1 in use)
16:20:23.636 [DEBUG] [org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter] Removed task artifact state for {} from context.
16:20:23.636 [DEBUG] [org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter] Finished executing task ':compileGroovy'
Thank you.

Ok I figured it out. Jason's answer gave me a clue. I opened terminal and ran ./gradlew --version and got this output:
Gradle 3.5-rc-2
Build time: 2017-03-27 15:56:23 UTC
Revision: ec63970cd167993d3dcda346a1d00a286a23b1c9
Groovy: 2.4.10
Ant: Apache Ant(TM) version 1.9.6 compiled on June 29 2015
JVM: 1.8.0_131 (Oracle Corporation 25.131-b11)
OS: Mac OS X 10.12.6 x86_64
So I noticed the Groovy version is 2.4.10 so I changed the gradle file to use this version, recompiled and the files were generated.

When I tried to run it I received the following error in addition to yours,
When I tried to run it I received the following error, "Caused by: groovy.lang.GroovyRuntimeException: Conflicting module versions. Module [groovy-all is loaded in version 2.4.7 and you are trying to load version 2.3.11"
I modified build.gradle and changed line 14 from
compile 'org.codehaus.groovy:groovy-all:2.3.11'
to
compile 'org.codehaus.groovy:groovy-all:2.4.7'

Related

Gradle Exec now throws "error=2, No such file or directory"

I have a repo https://github.com/ahoffer/geotools-tutorials.
I used to be able to run ./gradlew installJar without error.
A few months have gone by and ./gradlew installJar produces:
Caused by: java.io.IOException: Cannot run program "mvn install:install-file -Dfile="lib/jai_core-1.1.3.jar.zip" -DgroupId=javax.media -DartifactId=jai-core -Dversion=1.1.3 -Dpackaging=jar" (in directory "/projects/geotools-tutorials"): error=2, No such file or directory
at net.rubygrapefruit.platform.internal.DefaultProcessLauncher.start(DefaultProcessLauncher.java:25)
I can copy and paste the commanLine task to the shell and it runs fine:
/projects/geotools-tutorials$ mvn install:install-file
-Dfile="lib/jai_core-1.1.3.jar.zip" -DgroupId=javax.media -DartifactId=jai-core -Dversion=1.1.3 -Dpackaging=jar [INFO] BUILD SUCCESS
I do not know why it stopped working or how to get it working again. I am on Ubuntu 19.10.
Gradle 5.6.1
Build time: 2019-08-28 02:49:34 UTC
Revision: b6bd8e7934ca41d9e52610058aa7cb834df81fc4
Kotlin: 1.3.41
Groovy: 2.5.4
Ant: Apache Ant(TM) version 1.9.14 compiled on March 12 2019
JVM: 11.0.5-ea (Ubuntu 11.0.5-ea+10-post-Ubuntu-0ubuntu1)
OS: Linux 5.3.0-24-generic amd64
I don't know what version of gradle you were using for that task to have executed successfully, but this is the way to structure that commandLine:
commandLine 'mvn', 'install:install-file', '-Dfile=lib/jai_core-1.1.3.jar.zip', '-DgroupId=javax.media', '-DartifactId=jai-core', '-Dversion=1.1.3', '-Dpackaging=jar'
Tested and works with gradle 5.5

Corda - Gradle Error With Quasar When Upgrading to Corda 4.3

I've updated my build.gradle file to Corda 4.3, however applying this plugin...
apply plugin: 'net.corda.plugins.quasar-utils'
...causes the following error when trying to refresh gradle...
A problem occurred evaluating root project 'template'.
> Failed to apply plugin [id 'net.corda.plugins.quasar-utils']
> Could not create an instance of type net.corda.plugins.QuasarExtension_Decorated.
> No signature of method: org.gradle.api.internal.provider.DefaultPropertyState.convention() is applicable for argument types: (java.lang.String) values: [co.paralleluniverse]
Any ideas what is causing this?
I had the same problem executing Corda 4.4 release. Basically you have to update your gradle version to recognize some dependencies in gradle.
First of all, execute the comand: gradle -version
After that, you have to update your gradle version according to the gradle version supported by your current Corda version. In my case, It is supported by gradle version 5.4.1. So, to execute an upgrade, try this: ./gradlew wrapper --gradle-version 5.4.1
Next, check again your gradle version using ./gradlew --version (in the CorDapp directory)
Finally, you can execute your task. So, in my case I would like to execute a test with heap dump allocating more memory and check an OOM. I execute the follow command:
./gradlew test -Dlog4j.configurationFile=../config/test/log4j2.xml -Dcapsule.jvm.args=["-Xmx10G","-Xms512m","-XX:+UseG1GC","-XX:+HeapDumpOnOutOfMemoryError"]
That is it!
Have you tried with gradle-5.4.1?
Source : https://www.corda.net/blog/corda-version-upgrade-guide/

IntelliJ IDEA unable to resolve fine working gradle dependency

I'm currently working on a Kotlin project with Gradle (source code here). It's a Bukkit plugin which depends on a library I maintain (library source code here). When running ./gradlew assemble in a terminal, everything works fine and the build succeeds (log below).
$ ./gradlew assemble --console plain
> Task :compileKotlin
w: Some JAR files in the classpath have the Kotlin Runtime library bundled into them. This may cause difficult to debug problems if there's a different version of the Kotlin Runtime library in the classpath. Consider removing these libraries from the classpath
w: /home/axel/.gradle/caches/modules-2/files-2.1/com.github.axelrindle/PocketKnife/v1.3.0/b2303013bfd8e21c419f1d640ef374afc48e86af/PocketKnife-v1.3.0.jar: Library has Kotlin runtime bundled into it
> Task :compileJava NO-SOURCE
> Task :processResources
> Task :classes
> Task :inspectClassesForKotlinIC
> Task :jar
> Task :assemble
BUILD SUCCESSFUL in 5s
4 actionable tasks: 4 executed
But when working in IDEA, my library is the only one the IDE fails to resolve for whatever reason.
I've already tried the following steps:
Delete gradle/idea caches (~/.gradle/caches;.idea)
Reinstall IDEA
Delete IDEA config directory (.IdeaIC2019.1)
Reimport the project in IDEA
I've already read the following questions/answers, but none of them worked:
Getting Gradle dependencies in IntelliJ IDEA using Gradle build
Unable to resolve dependencies in IntelliJ IDEA 2018.1
Gradle dependencies not working in IntelliJ
IntelliJ won't recognize some imports from gradle project
Intellij: Gradle dependency not found
Also, my idea.log can be found here: https://pastebin.com/0Z5b3Wdp
Last but not least some version information:
IntelliJ IDEA 2019.1.3 (Community Edition)
Build #IC-191.7479.19, built on May 28, 2019
JRE: 1.8.0_202-release-1483-b58 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Linux 4.18.0-21-generic
$ ./gradlew --version
------------------------------------------------------------
Gradle 5.4.1
------------------------------------------------------------
Build time: 2019-04-26 08:14:42 UTC
Revision: 261d171646b36a6a28d5a19a69676cd098a4c19d
Kotlin: 1.3.21
Groovy: 2.5.4
Ant: Apache Ant(TM) version 1.9.13 compiled on July 10 2018
JVM: 12.0.1 (Oracle Corporation 12.0.1+12)
OS: Linux 4.18.0-21-generic amd64
After a lot of failed troubleshooting, I found out what the problem was. My library contained the bundled kotlin runtime, which was causing impossible to debug resolving issues with IDEA. I split up the project into multiple subprojects, where the actual api dependency does not bundle the kotlin runtime. This fixed my issues.
I just cloned your repository from https://github.com/axelrindle/Broadcaster-Plugin
In your build.gradle file you are referencing version 1.2.2 of your PocketKnife artefact, which does not exist in your GitHub. If you use an existing version like 1.2.1 IntelliJ can resolve the dependency.

Groovy grape not resolving artifacts in Maven central

Fresh install of Groovy and for some reason it isn't pulling artifacts from Maven central:
$ grape resolve org.apache.httpcomponents httpclient 4.2.1
Error in resolve:
Error grabbing Grapes -- [download failed: org.apache.httpcomponents#httpclient;4.2.1!httpclient.jar, download failed: org.apache.httpcomponents#httpcore;4.2.1!httpcore.jar, download failed: commons-logging#commons-logging;1.1.1!commons-logging.jar]
Complete -d debug log:
https://gist.github.com/mrobinet/a86073e35771cab55665
Environment:
$ groovy --version
Groovy Version: 2.4.4 JVM: 1.7.0_79 Vendor: Oracle Corporation OS: Mac OS X
The artifacts clearly exist:
https://repo1.maven.org/maven2/org/apache/httpcomponents/httpclient/4.1.2/
Things I've tried:
Adding Maven Central to ~/.groovy/grapeConfig.xml
grape -r https://repo1.maven.org/maven2 resolve org.apache.httpcomponents httpclient 4.2.1
Viewing the debug output, it doesn't even appear to be requesting it from central.
I recently ran into this again and was able to figure out the issue. I ended up filing a bug with Groovy: https://issues.apache.org/jira/browse/GROOVY-8655
The problem occurs when you have only a POM file for the artifact in your Maven local repository (no jar file).

How to run a single unit test using gradle wrapper 2.2.1 from command line

Using Android studio with gradle wrapper version 2.2.1, I am trying to run all the tests in one single test class, as well as a specific test inside that class and have tried using:
./gradlew test --tests DownloadsActivityTest
like the documentation suggests, as well as
-DandroidTest.single=DownloadsActivityTest
But neither of these versions work.
How do I run a single test class, and a single test from the command line using the gradle wrapper?
./gradlew --version
------------------------------------------------------------
Gradle 2.2.1
------------------------------------------------------------
Build time: 2014-11-24 09:45:35 UTC
Build number: none
Revision: 6fcb59c06f43a4e6b1bcb401f7686a8601a1fb4a
Groovy: 2.3.6
Ant: Apache Ant(TM) version 1.9.3 compiled on December 23 2013
JVM: 1.7.0_51 (Oracle Corporation 24.51-b03)
OS: Linux 3.17.6-200.fc20.x86_64 amd64
[16:33][j#localhost:~/myHomeDir]$ ./gradlew test --tests DownloadsActivityTest
WARNING: Dependency commons-logging:commons-logging:1.1.1 is ignored for debugTest as it may be conflicting with the internal version provided by Android.
In case of problem, please repackage it with jarjar to change the class packages
WARNING: Dependency org.apache.httpcomponents:httpclient:4.0.3 is ignored for debugTest as it may be conflicting with the internal version provided by Android.
In case of problem, please repackage it with jarjar to change the class packages
FAILURE: Build failed with an exception.
* What went wrong:
Problem configuring task :app:test from command line.
> Unknown command-line option '--tests'.
* Try:
Run gradlew help --task :app:test to get task usage details. Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 4.466 secs
To only run instrumentation tests (androidTests) in a specific test class, execute:
./gradlew app:connectedAndroidTest -Pandroid.testInstrumentationRunnerArguments.class=com.example.android.testing.blueprint.ui.espresso.EspressoTest
To only run local tests ("unit", JVM tests) in a specific test class or package execute:
./gradlew :app:testDebugUnitTest --tests "com.example.android.testing.blueprint.unit.integrationTests.*"
./gradlew :<module name>:test<CapitalCasedBuildVariant> --tests "<Test name pattern>"
It is important to specify the module name where the test lives, otherwise, when gradle builds dependent modules, it will attempt to test them, and might fail because none of the tests fit the test pattern:
No tests found for given includes: [FooTest]
Also, unless you specify the fully-qualified-name (FQN) of the test, your test name pattern should start with a *.
In my case, I have a module named app and a variant named localDebug, and I wanted to test FooTest, so I ran:
./gradlew :app:testLocalDebug --tests "*FooTest"
This is supported in Android Studio 1.1, using the Android Gradle plugin v1.1.0.
Follow the guide here
The Android Gradle plugin, as of 1.0.0, doesn't have support for running single Android tests. The feature request for it is filed at https://code.google.com/p/android/issues/detail?id=74196.
I know that better test support in general is very high on the post-1.0 priority list, but I can't say with any certainty when this will be implemented.

Resources