Groovy is a Java based syntax compatible object-oriented programming language. It is both a static and dynamic language with features similar to those of popular languages like Python and Ruby.

Popular New Releases in Groovy

gradle

7.4.2

rundeck

v4.1.0-20220420

gradle-versions-plugin

v0.42.0

shadow

fat-aar-android

v1.3.8

Popular Libraries in Groovy

gradle

by gradle doticongroovydoticon

star image 13299 doticonApache-2.0

Adaptable, fast automation for all

rundeck

by rundeck doticongroovydoticon

star image 4550 doticonApache-2.0

Enable Self-Service Operations: Give specific users access to your existing tools, services, and scripts

pipeline-examples

by jenkinsci doticongroovydoticon

star image 3675 doticonMIT

A collection of examples, tips and tricks and snippets of scripting for the Jenkins Pipeline plugin

gradle_plugin_android_aspectjx

by HujiangTechnology doticongroovydoticon

star image 3458 doticonApache-2.0

A Android gradle plugin that effects AspectJ on Android project and can hook methods in Kotlin, aar and jar file.

gradle-versions-plugin

by ben-manes doticongroovydoticon

star image 3228 doticonApache-2.0

Gradle plugin to discover dependency updates

shadow

by johnrengelman doticongroovydoticon

star image 2759 doticonApache-2.0

Gradle plugin to create fat/uber JARs, apply file transforms, and relocate packages for applications and libraries. Gradle version of Maven's Shade plugin.

SmartThingsPublic

by SmartThingsCommunity doticongroovydoticon

star image 2314 doticon

SmartThings open-source DeviceTypeHandlers and SmartApps code

asgard

by Netflix doticongroovydoticon

star image 2230 doticonApache-2.0

[Asgard is deprecated at Netflix. We use Spinnaker ( www.spinnaker.io ).] Web interface for application deployments and cloud management in Amazon Web Services (AWS). Binary download: http://github.com/Netflix/asgard/releases

fat-aar-android

by kezong doticongroovydoticon

star image 2188 doticonMIT

A gradle plugin that merge dependencies into the final aar file works with AGP 3.+

Trending New libraries in Groovy

skills-service

by NationalSecurityAgency doticongroovydoticon

star image 187 doticonApache-2.0

SkillTree is a micro-learning gamification platform supporting the rapid integration of a gamified tool training approach into new and existing applications.

AppInit

by bingoogolapple doticongroovydoticon

star image 149 doticon

AppInit 是一款 Android 应用初始化框架,基于组件化的设计思路,功能灵活,使用简单。

AndroidJunkCode

by qq549631030 doticongroovydoticon

star image 120 doticon

Android马甲包生成垃圾代码插件

bintray-publish

by panpf doticongroovydoticon

star image 100 doticon

Super easy way to publish your Android and Java artifacts to bintray.

hubitat-packagemanager

by dcmeglio doticongroovydoticon

star image 96 doticonBSD-3-Clause

jenkins-lib

by firstBitMarksistskaya doticongroovydoticon

star image 80 doticonMIT

Jenkins shared library для 1С:Предприятие 8

jenkinslibrary

by zeyangli doticongroovydoticon

star image 77 doticon

Jenkins共享库

jenkins-lib

by firstBitSemenovskaya doticongroovydoticon

star image 70 doticonMIT

Jenkins shared library для 1С:Предприятие 8

tasmota-connect

by hongtat doticongroovydoticon

star image 59 doticonGPL-3.0

Add your Tasmota devices as SmartThings devices

Top Authors in Groovy

1

grails-plugins

51 Libraries

star icon1176

2

kazurayam

39 Libraries

star icon55

3

UrbanCode

38 Libraries

star icon71

4

nebula-plugins

36 Libraries

star icon2139

5

binle

32 Libraries

star icon0

6

madhephaestus

32 Libraries

star icon34

7

AtlasOfLivingAustralia

30 Libraries

star icon28

8

wooga

29 Libraries

star icon22

9

grails

29 Libraries

star icon1564

10

jeffbrown

27 Libraries

star icon45

1

51 Libraries

star icon1176

2

39 Libraries

star icon55

3

38 Libraries

star icon71

4

36 Libraries

star icon2139

5

32 Libraries

star icon0

6

32 Libraries

star icon34

7

30 Libraries

star icon28

8

29 Libraries

star icon22

9

29 Libraries

star icon1564

10

27 Libraries

star icon45

Trending Kits in Groovy

No Trending Kits are available at this moment for Groovy

Trending Discussions on Groovy

Jenkins/groovy: How to pretty-print a net.sf.json.JSONObject with null?

Java, Intellij IDEA problem Unrecognized option: --add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED

Unable to load class AndroidComponentsExtension after upgrading the Android Gradle Plugin 7.1

UnknownPluginException using Google Play Services and Plugins DSL

Ionic Cordova Android: No usable Android build tools found. Highest 30.x installed version is 30.0.2; minimum version required is 30.0.3

How to make Kotlin Multiplatform work with Android Studio's project view?

Jenkins log4j vulnerability testing from pipeline job

Why is "continuous-integration/jenkins/pr-merge" not being triggered by GitHub on a pull request?

How to bring list of jenkins nodes to Active choice parameter and present only those for the current logged in user

Kafka integration tests in Gradle runs into GitHub Actions

QUESTION

Jenkins/groovy: How to pretty-print a net.sf.json.JSONObject with null?

Asked 2022-Mar-31 at 11:16

Working on a Jenkins pipeline, I observed what looks like infinite recursion causing a stack overflow when I use JsonOutput.toJson() on a net.sf.json.JSONObject that slurped a JSON string containing null.

The following minimal code demonstrates the problem:

1// Jenkinsfile
2@Library('libs@dev') libs
3
4import groovy.json.JsonOutput
5
6pipeline {
7  agent any
8
9  stages {
10    stage( "json" ) {
11      steps {
12        script {
13          my_lib.to_json_handbuilt_linkedhashmap()
14          my_lib.to_json_readjson()
15          my_lib.to_json_readjson_as_linkedhashmap()
16        }
17      }
18    }
19  }
20}
21
1// Jenkinsfile
2@Library('libs@dev') libs
3
4import groovy.json.JsonOutput
5
6pipeline {
7  agent any
8
9  stages {
10    stage( "json" ) {
11      steps {
12        script {
13          my_lib.to_json_handbuilt_linkedhashmap()
14          my_lib.to_json_readjson()
15          my_lib.to_json_readjson_as_linkedhashmap()
16        }
17      }
18    }
19  }
20}
21// vars/my_lib.groovy
22import groovy.json.JsonOutput
23
24def asMap(j) {
25  return j as LinkedHashMap
26}
27
28// This function is successful.
29def to_json_handbuilt_linkedhashmap() {
30  def d = [:]
31  d.issues = null
32
33  echo "---- handmade LinkedHashMap ----"
34  echo "d ${d}"
35  echo "d.getClass() ${d.getClass()}"
36  echo "JsonOutput.toJson(d) ${JsonOutput.toJson(d)}"
37}
38
39// This function fails from infinite recursion causing a stack overflow.
40def to_json_readjson() {
41  def d = readJSON(text: '{ "issues" : null }')
42
43  echo "---- readJSON ----"
44  echo "d ${d}"
45  echo "d.getClass() ${d.getClass()}"
46  echo "JsonOutput.toJson(d) ${JsonOutput.toJson(d)}"
47}
48
49// This function also fails from infinite recursion causing a stack overflow.
50def to_json_readjson_as_linkedhashmap() {
51  def d = asMap(readJSON(text: '{ "issues" : null }'))
52
53  echo "---- readJSON -> asMap ----"
54  echo "d ${d}"
55  echo "d.getClass() ${d.getClass()}"
56  echo "JsonOutput.toJson(d) ${JsonOutput.toJson(d)}"
57}
58

In the code above, to_json_readjson() fails with a stack overflow when JsonOutput.toJson() is called with the net.sf.json.JSONObject returned by readJSON(text: '{ "issues" : null }'). The Jenkins console output is at the end of this post.

In to_json_handbuilt_linkedhashmap() JsonOutput.toJson() is successful when called with a handcrafted LinkedHashMap equivalent to { "issues" : null }.

Lastly, in to_json_readjson_as_linkedhashmap(), JsonOutput.toJson() again fails with a stack overflow when called with a LinkedHashMap created from a net.sf.json.JSONObject.

Question:
Can someone please explain what's causing the stack overflow when readJSON() and/or JsonOutput.toJson() are used with a JSON string that has null?

Because my handcrafted LinkedHashMap was successful with JsonOutput.toJson(), I thought the problem was passing JsonOutput.toJson() a net.sf.json.JSONObject.
But I think that theory is ruled out because in to_json_readjson_as_linkedhashmap(), I give JsonOutput.toJson() a LinkedHashMap, albeit created from a net.sf.json.JSONObject.
The problem would appear to be some combination of readJSON() and/or JsonOutput.toJson() that I'm failing to grasp.

I tried, but have given up trying to use a JsonSlurper, because I'm unable to even create an instance of one.

The (truncated) stack overflow error likely showing infinite recursion:

1// Jenkinsfile
2@Library('libs@dev') libs
3
4import groovy.json.JsonOutput
5
6pipeline {
7  agent any
8
9  stages {
10    stage( "json" ) {
11      steps {
12        script {
13          my_lib.to_json_handbuilt_linkedhashmap()
14          my_lib.to_json_readjson()
15          my_lib.to_json_readjson_as_linkedhashmap()
16        }
17      }
18    }
19  }
20}
21// vars/my_lib.groovy
22import groovy.json.JsonOutput
23
24def asMap(j) {
25  return j as LinkedHashMap
26}
27
28// This function is successful.
29def to_json_handbuilt_linkedhashmap() {
30  def d = [:]
31  d.issues = null
32
33  echo "---- handmade LinkedHashMap ----"
34  echo "d ${d}"
35  echo "d.getClass() ${d.getClass()}"
36  echo "JsonOutput.toJson(d) ${JsonOutput.toJson(d)}"
37}
38
39// This function fails from infinite recursion causing a stack overflow.
40def to_json_readjson() {
41  def d = readJSON(text: '{ "issues" : null }')
42
43  echo "---- readJSON ----"
44  echo "d ${d}"
45  echo "d.getClass() ${d.getClass()}"
46  echo "JsonOutput.toJson(d) ${JsonOutput.toJson(d)}"
47}
48
49// This function also fails from infinite recursion causing a stack overflow.
50def to_json_readjson_as_linkedhashmap() {
51  def d = asMap(readJSON(text: '{ "issues" : null }'))
52
53  echo "---- readJSON -> asMap ----"
54  echo "d ${d}"
55  echo "d.getClass() ${d.getClass()}"
56  echo "JsonOutput.toJson(d) ${JsonOutput.toJson(d)}"
57}
58Posting build status of FAILED to bitbucket.company.comjava.lang.StackOverflowError
59    at java.io.PrintStream.flush(PrintStream.java:338)
60    at sun.nio.cs.StreamEncoder.implFlush(StreamEncoder.java:297)
61    at sun.nio.cs.StreamEncoder.flush(StreamEncoder.java:141)
62    at java.io.OutputStreamWriter.flush(OutputStreamWriter.java:229)
63    at java.util.logging.StreamHandler.flush(StreamHandler.java:259)
64    at java.util.logging.ConsoleHandler.publish(ConsoleHandler.java:117)
65    at java.util.logging.Logger.log(Logger.java:738)
66    at java.util.logging.Logger.doLog(Logger.java:765)
67    at java.util.logging.Logger.throwing(Logger.java:1447)
68    at org.codehaus.groovy.runtime.DefaultGroovyMethods.getProperties(DefaultGroovyMethods.java:391)
69    at groovy.json.JsonOutput.getObjectProperties(JsonOutput.java:327)
70    at groovy.json.JsonOutput.writeObject(JsonOutput.java:320)
71    at groovy.json.JsonOutput.writeMap(JsonOutput.java:458)
72    at groovy.json.JsonOutput.writeObject(JsonOutput.java:321)
73    at groovy.json.JsonOutput.writeMap(JsonOutput.java:458)
74    at groovy.json.JsonOutput.writeObject(JsonOutput.java:321)
75    at groovy.json.JsonOutput.writeMap(JsonOutput.java:458)
76    at groovy.json.JsonOutput.writeObject(JsonOutput.java:321)
77    at groovy.json.JsonOutput.writeMap(JsonOutput.java:458)
78    at groovy.json.JsonOutput.writeObject(JsonOutput.java:321)
79    at groovy.json.JsonOutput.writeMap(JsonOutput.java:458)
80    at groovy.json.JsonOutput.writeObject(JsonOutput.java:321)
81    at groovy.json.JsonOutput.writeMap(JsonOutput.java:458)
82    at groovy.json.JsonOutput.writeObject(JsonOutput.java:321)
83

ANSWER

Answered 2022-Mar-31 at 11:16

Can you sidestep this immediate problem by using readJSON's returnPojo: true parameter, thereby solving your overall task sooner?

Getting plain old nulls rather than net.sf.json.JSONNull objects really helped me today, though my problem involved producing CSV rather than using JsonOutput.

Source https://stackoverflow.com/questions/71059703

QUESTION

Java, Intellij IDEA problem Unrecognized option: --add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED

Asked 2022-Mar-26 at 15:23

I have newly installed

1IntelliJ IDEA 2021.2 (Ultimate Edition)
2Build #IU-212.4746.92, built on July 27, 2021
3Licensed to XXXXXX
4Subscription is active until August 15, 2021.
5Runtime version: 11.0.11+9-b1504.13 amd64
6VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
7Linux 5.4.0-80-generic
8GC: G1 Young Generation, G1 Old Generation
9Memory: 2048M
10Cores: 3
11
12Kotlin: 212-1.5.10-release-IJ4746.92
13Current Desktop: X-Cinnamon
14

I cloned project I work with on other workstation without issues, but cannot start any class with main method and IDEA says:

1IntelliJ IDEA 2021.2 (Ultimate Edition)
2Build #IU-212.4746.92, built on July 27, 2021
3Licensed to XXXXXX
4Subscription is active until August 15, 2021.
5Runtime version: 11.0.11+9-b1504.13 amd64
6VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
7Linux 5.4.0-80-generic
8GC: G1 Young Generation, G1 Old Generation
9Memory: 2048M
10Cores: 3
11
12Kotlin: 212-1.5.10-release-IJ4746.92
13Current Desktop: X-Cinnamon
14Abnormal build process termination: 
15/usr/lib/jvm/java-1.8.0-openjdk-amd64/bin/java -Xmx700m -Djava.awt.headless=true -Djava.endorsed.dirs=\"\" -Dcompile.parallel=false -Drebuild.on.dependency.change=true -Djdt.compiler.useSingleThread=true -Daether.connector.resumeDownloads=false -Dio.netty.initialSeedUniquifier=-5972351880001011455 -Dfile.encoding=UTF-8 -Duser.language=en -Duser.country=US -Didea.paths.selector=IntelliJIdea2021.2 -Didea.home.path=/home/pm/idea-IU-212.4746.92 -Didea.config.path=/home/pm/.config/JetBrains/IntelliJIdea2021.2 -Didea.plugins.path=/home/pm/.local/share/JetBrains/IntelliJIdea2021.2 -Djps.log.dir=/home/pm/.cache/JetBrains/IntelliJIdea2021.2/log/build-log -Djps.fallback.jdk.home=/home/pm/idea-IU-212.4746.92/jbr -Djps.fallback.jdk.version=11.0.11 -Dio.netty.noUnsafe=true -Djava.io.tmpdir=/home/pm/.cache/JetBrains/IntelliJIdea2021.2/compile-server/rfg-survey-api_cc70fc05/_temp_ -Djps.backward.ref.index.builder=true -Djps.track.ap.dependencies=false --add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED --add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED --add-opens=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED --add-opens=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED --add-opens=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED --add-opens=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED --add-opens=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED --add-opens=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED --add-opens=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED --add-opens=jdk.compiler/com.sun.tools.javac.jvm=ALL-UNNAMED -Dtmh.instrument.annotations=true -Dtmh.generate.line.numbers=true -Dkotlin.incremental.compilation=true -Dkotlin.incremental.compilation.js=true -Dkotlin.daemon.enabled -Dkotlin.daemon.client.alive.path=\"/tmp/kotlin-idea-12426594439704512301-is-running\" -classpath /home/pm/idea-IU-212.4746.92/plugins/java/lib/jps-launcher.jar:/usr/lib/jvm/java-1.8.0-openjdk-amd64/lib/tools.jar org.jetbrains.jps.cmdline.Launcher /home/pm/idea-IU-212.4746.92/lib/slf4j.jar:/home/pm/idea-IU-212.4746.92/lib/idea_rt.jar:/home/pm/idea-IU-212.4746.92/lib/platform-api.jar:/home/pm/idea-IU-212.4746.92/plugins/java/lib/maven-resolver-transport-file-1.3.3.jar:/home/pm/idea-IU-212.4746.92/lib/forms_rt.jar:/home/pm/idea-IU-212.4746.92/lib/util.jar:/home/pm/idea-IU-212.4746.92/lib/annotations.jar:/home/pm/idea-IU-212.4746.92/lib/3rd-party.jar:/home/pm/idea-IU-212.4746.92/lib/kotlin-stdlib-jdk8.jar:/home/pm/idea-IU-212.4746.92/plugins/java/lib/maven-resolver-connector-basic-1.3.3.jar:/home/pm/idea-IU-212.4746.92/lib/jna-platform.jar:/home/pm/idea-IU-212.4746.92/lib/protobuf-java-3.15.8.jar:/home/pm/idea-IU-212.4746.92/plugins/java/lib/jps-builders-6.jar:/home/pm/idea-IU-212.4746.92/plugins/java/lib/javac2.jar:/home/pm/idea-IU-212.4746.92/plugins/java/lib/aether-dependency-resolver.jar:/home/pm/idea-IU-212.4746.92/plugins/java/lib/jps-builders.jar:/home/pm/idea-IU-212.4746.92/plugins/java/lib/jps-javac-extension-1.jar:/home/pm/idea-IU-212.4746.92/lib/jna.jar:/home/pm/idea-IU-212.4746.92/lib/jps-model.jar:/home/pm/idea-IU-212.4746.92/plugins/java/lib/maven-resolver-transport-http-1.3.3.jar:/home/pm/idea-IU-212.4746.92/plugins/JavaEE/lib/jasper-v2-rt.jar:/home/pm/idea-IU-212.4746.92/plugins/Kotlin/lib/kotlin-reflect.jar:/home/pm/idea-IU-212.4746.92/plugins/Kotlin/lib/kotlin-plugin.jar:/home/pm/idea-IU-212.4746.92/plugins/ant/lib/ant-jps.jar:/home/pm/idea-IU-212.4746.92/plugins/uiDesigner/lib/jps/java-guiForms-jps.jar:/home/pm/idea-IU-212.4746.92/plugins/eclipse/lib/eclipse-jps.jar:/home/pm/idea-IU-212.4746.92/plugins/eclipse/lib/eclipse-common.jar:/home/pm/idea-IU-212.4746.92/plugins/IntelliLang/lib/java-langInjection-jps.jar:/home/pm/idea-IU-212.4746.92/plugins/Groovy/lib/groovy-jps.jar:/home/pm/idea-IU-212.4746.92/plugins/Groovy/lib/groovy-constants-rt.jar:/home/pm/idea-IU-212.4746.92/plugins/maven/lib/maven-jps.jar:/home/pm/idea-IU-212.4746.92/plugins/gradle-java/lib/gradle-jps.jar:/home/pm/idea-IU-212.4746.92/plugins/devkit/lib/devkit-jps.jar:/home/pm/idea-IU-212.4746.92/plugins/javaFX/lib/javaFX-jps.jar:/home/pm/idea-IU-212.4746.92/plugins/javaFX/lib/javaFX-common.jar:/home/pm/idea-IU-212.4746.92/plugins/JavaEE/lib/javaee-jps.jar:/home/pm/idea-IU-212.4746.92/plugins/webSphereIntegration/lib/jps/javaee-appServers-websphere-jps.jar:/home/pm/idea-IU-212.4746.92/plugins/weblogicIntegration/lib/jps/javaee-appServers-weblogic-jps.jar:/home/pm/idea-IU-212.4746.92/plugins/JPA/lib/jps/javaee-jpa-jps.jar:/home/pm/idea-IU-212.4746.92/plugins/Grails/lib/groovy-grails-jps.jar:/home/pm/idea-IU-212.4746.92/plugins/Grails/lib/groovy-grails-compilerPatch.jar:/home/pm/idea-IU-212.4746.92/plugins/Kotlin/lib/jps/kotlin-jps-plugin.jar:/home/pm/idea-IU-212.4746.92/plugins/Kotlin/lib/kotlin-jps-common.jar:/home/pm/idea-IU-212.4746.92/plugins/Kotlin/lib/kotlin-common.jar org.jetbrains.jps.cmdline.BuildMain 127.0.0.1 34781 9f0681bb-da2a-48db-8344-900ddeb29804 /home/pm/.cache/JetBrains/IntelliJIdea2021.2/compile-server
16Unrecognized option: --add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED
17Error: Could not create the Java Virtual Machine.
18Error: A fatal exception has occurred. Program will exit.
19

I found other comment to check Lombok works and I see it is fine.

How to fix the problem?

ANSWER

Answered 2021-Jul-28 at 07:22

You are running the project via Java 1.8 and add the --add-opens option to the runner. However Java 1.8 does not support it.

So, the first option is to use Java 11 to run the project, as Java 11 can recognize this VM option.

Another solution is to find a place where --add-opens is added and remove it. Check Run configuration in IntelliJ IDEA (VM options field) and Maven/Gradle configuration files for argLine (Maven) and jvmArgs (Gradle)

Source https://stackoverflow.com/questions/68554693

QUESTION

Unable to load class AndroidComponentsExtension after upgrading the Android Gradle Plugin 7.1

Asked 2022-Mar-07 at 20:34

I recently downloaded Android Studio Bumblebee and it helpfully asked whether I wanted to upgrade to Android Gradle Plugin 7.1.0, the version that shipped alongside Android Studio Bumblebee.

After upgrading, I get a build error:

1Unable to load class 'com.android.build.api.extension.AndroidComponentsExtension'.
2
3This is an unexpected error. Please file a bug containing the idea.log file.
4

And looking at the idea.log file, I see:

1Unable to load class 'com.android.build.api.extension.AndroidComponentsExtension'.
2
3This is an unexpected error. Please file a bug containing the idea.log file.
4A problem occurred evaluating project ':main'.
5    at org.gradle.initialization.exception.DefaultExceptionAnalyser.transform(DefaultExceptionAnalyser.java:103)
6    ...
7Caused by: org.gradle.api.GradleScriptException: A problem occurred evaluating project ':main'.
8    at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:93)
9    ...
10Caused by: java.lang.NoClassDefFoundError: com/android/build/api/extension/AndroidComponentsExtension
11    at androidx.navigation.safeargs.gradle.SafeArgsPlugin.apply(SafeArgsPlugin.kt:73)
12    at androidx.navigation.safeargs.gradle.SafeArgsPlugin.apply(SafeArgsPlugin.kt:42)
13    ...
14Caused by: java.lang.ClassNotFoundException: com.android.build.api.extension.AndroidComponentsExtension
15

Which means I can't run my app and I need to downgrade the AGP 7.0 to get things working again. How do I fix this and upgrade to Android Gradle Plugin 7.1.0?

ANSWER

Answered 2022-Feb-11 at 04:05

Updating Navigation Safe Args

These lines are the important ones to look at:

1Unable to load class 'com.android.build.api.extension.AndroidComponentsExtension'.
2
3This is an unexpected error. Please file a bug containing the idea.log file.
4A problem occurred evaluating project ':main'.
5    at org.gradle.initialization.exception.DefaultExceptionAnalyser.transform(DefaultExceptionAnalyser.java:103)
6    ...
7Caused by: org.gradle.api.GradleScriptException: A problem occurred evaluating project ':main'.
8    at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:93)
9    ...
10Caused by: java.lang.NoClassDefFoundError: com/android/build/api/extension/AndroidComponentsExtension
11    at androidx.navigation.safeargs.gradle.SafeArgsPlugin.apply(SafeArgsPlugin.kt:73)
12    at androidx.navigation.safeargs.gradle.SafeArgsPlugin.apply(SafeArgsPlugin.kt:42)
13    ...
14Caused by: java.lang.ClassNotFoundException: com.android.build.api.extension.AndroidComponentsExtension
15Caused by: java.lang.NoClassDefFoundError: com/android/build/api/extension/AndroidComponentsExtension
16    at androidx.navigation.safeargs.gradle.SafeArgsPlugin.apply(SafeArgsPlugin.kt:73)
17    at androidx.navigation.safeargs.gradle.SafeArgsPlugin.apply(SafeArgsPlugin.kt:42)
18

This indicates that the error is coming from the Navigation Safe Args plugin.

As per the Android Gradle Plugin 7.1.0 release notes:

AGP APIs that the Navigation Safe Args Gradle plugin depend on have been removed. AGP 7.1 does not work with Navigation Safe Args versions 2.4.0-rc1 or 2.4.0, but will work with versions 2.5.0-alpha01 and 2.4.1. In the meantime, as a workaround, you can use AGP 7.1 with a snapshot build of Navigation Safe Args, Navigation 2.5.0-SNAPSHOT. To use the snapshot build, follow the snapshot instructions with build id #8054565.

As Navigation 2.4.1 is now available, you can upgrade to that version of Navigation to gain the fix:

Backported from Navigation 2.5.0-alpha01: Safe Args now depends on Android Gradle Plugin version 7.0.4. This means that Navigation Safe Args will no longer be compatible with Android Studio versions prior to 7.0, but is now compatible with Android Gradle Plugin 7.1.0 and higher.

1Unable to load class 'com.android.build.api.extension.AndroidComponentsExtension'.
2
3This is an unexpected error. Please file a bug containing the idea.log file.
4A problem occurred evaluating project ':main'.
5    at org.gradle.initialization.exception.DefaultExceptionAnalyser.transform(DefaultExceptionAnalyser.java:103)
6    ...
7Caused by: org.gradle.api.GradleScriptException: A problem occurred evaluating project ':main'.
8    at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:93)
9    ...
10Caused by: java.lang.NoClassDefFoundError: com/android/build/api/extension/AndroidComponentsExtension
11    at androidx.navigation.safeargs.gradle.SafeArgsPlugin.apply(SafeArgsPlugin.kt:73)
12    at androidx.navigation.safeargs.gradle.SafeArgsPlugin.apply(SafeArgsPlugin.kt:42)
13    ...
14Caused by: java.lang.ClassNotFoundException: com.android.build.api.extension.AndroidComponentsExtension
15Caused by: java.lang.NoClassDefFoundError: com/android/build/api/extension/AndroidComponentsExtension
16    at androidx.navigation.safeargs.gradle.SafeArgsPlugin.apply(SafeArgsPlugin.kt:73)
17    at androidx.navigation.safeargs.gradle.SafeArgsPlugin.apply(SafeArgsPlugin.kt:42)
18dependencies {
19    classpath 'com.android.tools.build:gradle:7.1.0'
20
21    // Update this line to use 2.4.1
22    classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.4.1"
23}
24

Note that you should always use the same version of the Navigation library as the Safe Args plugin (i.e., your app should also use Navigation 2.4.1): you should not try to use the Navigation 2.4.1+ Safe Args plugin with an earlier version of Navigation (such as 2.3.5).

Note on Firebase Perf Plugin

Note that you might see this same error when you are using:

1Unable to load class 'com.android.build.api.extension.AndroidComponentsExtension'.
2
3This is an unexpected error. Please file a bug containing the idea.log file.
4A problem occurred evaluating project ':main'.
5    at org.gradle.initialization.exception.DefaultExceptionAnalyser.transform(DefaultExceptionAnalyser.java:103)
6    ...
7Caused by: org.gradle.api.GradleScriptException: A problem occurred evaluating project ':main'.
8    at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:93)
9    ...
10Caused by: java.lang.NoClassDefFoundError: com/android/build/api/extension/AndroidComponentsExtension
11    at androidx.navigation.safeargs.gradle.SafeArgsPlugin.apply(SafeArgsPlugin.kt:73)
12    at androidx.navigation.safeargs.gradle.SafeArgsPlugin.apply(SafeArgsPlugin.kt:42)
13    ...
14Caused by: java.lang.ClassNotFoundException: com.android.build.api.extension.AndroidComponentsExtension
15Caused by: java.lang.NoClassDefFoundError: com/android/build/api/extension/AndroidComponentsExtension
16    at androidx.navigation.safeargs.gradle.SafeArgsPlugin.apply(SafeArgsPlugin.kt:73)
17    at androidx.navigation.safeargs.gradle.SafeArgsPlugin.apply(SafeArgsPlugin.kt:42)
18dependencies {
19    classpath 'com.android.tools.build:gradle:7.1.0'
20
21    // Update this line to use 2.4.1
22    classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.4.1"
23}
24classpath "com.google.firebase:perf-plugin:1.4.0"
25

With an idea.log of that states:

1Unable to load class 'com.android.build.api.extension.AndroidComponentsExtension'.
2
3This is an unexpected error. Please file a bug containing the idea.log file.
4A problem occurred evaluating project ':main'.
5    at org.gradle.initialization.exception.DefaultExceptionAnalyser.transform(DefaultExceptionAnalyser.java:103)
6    ...
7Caused by: org.gradle.api.GradleScriptException: A problem occurred evaluating project ':main'.
8    at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:93)
9    ...
10Caused by: java.lang.NoClassDefFoundError: com/android/build/api/extension/AndroidComponentsExtension
11    at androidx.navigation.safeargs.gradle.SafeArgsPlugin.apply(SafeArgsPlugin.kt:73)
12    at androidx.navigation.safeargs.gradle.SafeArgsPlugin.apply(SafeArgsPlugin.kt:42)
13    ...
14Caused by: java.lang.ClassNotFoundException: com.android.build.api.extension.AndroidComponentsExtension
15Caused by: java.lang.NoClassDefFoundError: com/android/build/api/extension/AndroidComponentsExtension
16    at androidx.navigation.safeargs.gradle.SafeArgsPlugin.apply(SafeArgsPlugin.kt:73)
17    at androidx.navigation.safeargs.gradle.SafeArgsPlugin.apply(SafeArgsPlugin.kt:42)
18dependencies {
19    classpath 'com.android.tools.build:gradle:7.1.0'
20
21    // Update this line to use 2.4.1
22    classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.4.1"
23}
24classpath "com.google.firebase:perf-plugin:1.4.0"
25Caused by: java.lang.NoClassDefFoundError: com/android/build/api/extension/AndroidComponentsExtension
26    at com.google.firebase.perf.plugin.FirebasePerfClassVisitorFactory.registerForProject(FirebasePerfClassVisitorFactory.java:54)
27    at com.google.firebase.perf.plugin.FirebasePerfPlugin.perform(FirebasePerfPlugin.java:145)
28    at com.google.firebase.perf.plugin.FirebasePerfPlugin.lambda$apply$0(FirebasePerfPlugin.java:107)
29

As per the Firebase Perf Plugin 1.4.1 Release Notes:

Migrated away from the deprecated Android Gradle plugin APIs.

So you should upgrade to 1.4.1:

1Unable to load class 'com.android.build.api.extension.AndroidComponentsExtension'.
2
3This is an unexpected error. Please file a bug containing the idea.log file.
4A problem occurred evaluating project ':main'.
5    at org.gradle.initialization.exception.DefaultExceptionAnalyser.transform(DefaultExceptionAnalyser.java:103)
6    ...
7Caused by: org.gradle.api.GradleScriptException: A problem occurred evaluating project ':main'.
8    at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:93)
9    ...
10Caused by: java.lang.NoClassDefFoundError: com/android/build/api/extension/AndroidComponentsExtension
11    at androidx.navigation.safeargs.gradle.SafeArgsPlugin.apply(SafeArgsPlugin.kt:73)
12    at androidx.navigation.safeargs.gradle.SafeArgsPlugin.apply(SafeArgsPlugin.kt:42)
13    ...
14Caused by: java.lang.ClassNotFoundException: com.android.build.api.extension.AndroidComponentsExtension
15Caused by: java.lang.NoClassDefFoundError: com/android/build/api/extension/AndroidComponentsExtension
16    at androidx.navigation.safeargs.gradle.SafeArgsPlugin.apply(SafeArgsPlugin.kt:73)
17    at androidx.navigation.safeargs.gradle.SafeArgsPlugin.apply(SafeArgsPlugin.kt:42)
18dependencies {
19    classpath 'com.android.tools.build:gradle:7.1.0'
20
21    // Update this line to use 2.4.1
22    classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.4.1"
23}
24classpath "com.google.firebase:perf-plugin:1.4.0"
25Caused by: java.lang.NoClassDefFoundError: com/android/build/api/extension/AndroidComponentsExtension
26    at com.google.firebase.perf.plugin.FirebasePerfClassVisitorFactory.registerForProject(FirebasePerfClassVisitorFactory.java:54)
27    at com.google.firebase.perf.plugin.FirebasePerfPlugin.perform(FirebasePerfPlugin.java:145)
28    at com.google.firebase.perf.plugin.FirebasePerfPlugin.lambda$apply$0(FirebasePerfPlugin.java:107)
29classpath "com.google.firebase:perf-plugin:1.4.1"
30

Source https://stackoverflow.com/questions/70857476

QUESTION

UnknownPluginException using Google Play Services and Plugins DSL

Asked 2022-Feb-19 at 05:20

I'm creating a new application in Android Studio Bumblebee and this defaults to using the new Groovy DSL plugin management in settings.gradle.

I need to be able to use Google Play Services to enable Firebase functionality, however I am running into a build error when applying the com.google.gms.google-play-services plugin using the documentation here: Google Play Services Readme

I have added the following to my settings.gradle file:

1pluginManagement {
2    repositories {
3        gradlePluginPortal()
4        google()
5    }
6    plugins {
7        id 'com.android.application' version '7.1.0-alpha13'
8        id 'com.android.library' version '7.1.0-alpha13'
9        id 'org.jetbrains.kotlin.android' version '1.5.31'
10        id 'com.google.gms.google-services' version '4.3.10'
11    }
12}
13

and the following to my app's build.gradle file:

1pluginManagement {
2    repositories {
3        gradlePluginPortal()
4        google()
5    }
6    plugins {
7        id 'com.android.application' version '7.1.0-alpha13'
8        id 'com.android.library' version '7.1.0-alpha13'
9        id 'org.jetbrains.kotlin.android' version '1.5.31'
10        id 'com.google.gms.google-services' version '4.3.10'
11    }
12}
13plugins {
14    id 'com.android.application'
15    id 'org.jetbrains.kotlin.android'
16    id 'com.google.gms.google-services'
17}
18

however when I build the application, I get the following UnknownPluginException:

1pluginManagement {
2    repositories {
3        gradlePluginPortal()
4        google()
5    }
6    plugins {
7        id 'com.android.application' version '7.1.0-alpha13'
8        id 'com.android.library' version '7.1.0-alpha13'
9        id 'org.jetbrains.kotlin.android' version '1.5.31'
10        id 'com.google.gms.google-services' version '4.3.10'
11    }
12}
13plugins {
14    id 'com.android.application'
15    id 'org.jetbrains.kotlin.android'
16    id 'com.google.gms.google-services'
17}
18Plugin [id: 'com.google.gms.google-services', version: '4.3.10'] was not found in any of the following sources:
19
20* Try:
21Run with --info or --debug option to get more log output. Run with --scan to get full insights.
22
23* Exception is:
24org.gradle.api.plugins.UnknownPluginException: Plugin [id: 'com.google.gms.google-services', version: '4.3.10'] was not found in any of the following sources:
25
26- Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
27- Plugin Repositories (could not resolve plugin artifact 'com.google.gms.google-services:com.google.gms.google-services.gradle.plugin:4.3.10')
28  Searched in the following repositories:
29    Gradle Central Plugin Repository
30    Google
31

I have also tried the legacy method of classpath etc. but this results in a much longer error message regarding dependency resolution.

I'm not sure what I am doing wrong.

ANSWER

Answered 2021-Oct-27 at 18:47

Adding the google-services plugin to the plugins {} block is causing errors. The alternate way that I've found is:

  1. First, in your root build file (not the one in the app folder), inside the buildscript {} block, add this
1pluginManagement {
2    repositories {
3        gradlePluginPortal()
4        google()
5    }
6    plugins {
7        id 'com.android.application' version '7.1.0-alpha13'
8        id 'com.android.library' version '7.1.0-alpha13'
9        id 'org.jetbrains.kotlin.android' version '1.5.31'
10        id 'com.google.gms.google-services' version '4.3.10'
11    }
12}
13plugins {
14    id 'com.android.application'
15    id 'org.jetbrains.kotlin.android'
16    id 'com.google.gms.google-services'
17}
18Plugin [id: 'com.google.gms.google-services', version: '4.3.10'] was not found in any of the following sources:
19
20* Try:
21Run with --info or --debug option to get more log output. Run with --scan to get full insights.
22
23* Exception is:
24org.gradle.api.plugins.UnknownPluginException: Plugin [id: 'com.google.gms.google-services', version: '4.3.10'] was not found in any of the following sources:
25
26- Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
27- Plugin Repositories (could not resolve plugin artifact 'com.google.gms.google-services:com.google.gms.google-services.gradle.plugin:4.3.10')
28  Searched in the following repositories:
29    Gradle Central Plugin Repository
30    Google
31buildscript {
32 repositories {
33   google()
34   mavenCentral()
35 }
36 dependencies {
37   classpath 'com.google.gms:google-services:4.3.10'
38 }
39}
40
  1. In the build file in the app folder, apply the plugin like this,
1pluginManagement {
2    repositories {
3        gradlePluginPortal()
4        google()
5    }
6    plugins {
7        id 'com.android.application' version '7.1.0-alpha13'
8        id 'com.android.library' version '7.1.0-alpha13'
9        id 'org.jetbrains.kotlin.android' version '1.5.31'
10        id 'com.google.gms.google-services' version '4.3.10'
11    }
12}
13plugins {
14    id 'com.android.application'
15    id 'org.jetbrains.kotlin.android'
16    id 'com.google.gms.google-services'
17}
18Plugin [id: 'com.google.gms.google-services', version: '4.3.10'] was not found in any of the following sources:
19
20* Try:
21Run with --info or --debug option to get more log output. Run with --scan to get full insights.
22
23* Exception is:
24org.gradle.api.plugins.UnknownPluginException: Plugin [id: 'com.google.gms.google-services', version: '4.3.10'] was not found in any of the following sources:
25
26- Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
27- Plugin Repositories (could not resolve plugin artifact 'com.google.gms.google-services:com.google.gms.google-services.gradle.plugin:4.3.10')
28  Searched in the following repositories:
29    Gradle Central Plugin Repository
30    Google
31buildscript {
32 repositories {
33   google()
34   mavenCentral()
35 }
36 dependencies {
37   classpath 'com.google.gms:google-services:4.3.10'
38 }
39}
40apply plugin: 'com.google.gms.google-services'
41

In step 1, using mavenCentral() is necessary as the google-services plugin downloads the linked dependencies like gson from maven central :)

Source https://stackoverflow.com/questions/69701090

QUESTION

Ionic Cordova Android: No usable Android build tools found. Highest 30.x installed version is 30.0.2; minimum version required is 30.0.3

Asked 2022-Feb-04 at 19:40

I have updated Cordova Android to the latest (10.1.1) and now when I build I get:

No usable Android build tools found. Highest 30.x installed version is 30.0.2; minimum version required is 30.0.3

I have the following reported when I start the build:

1Checking Java JDK and Android SDK versions
2ANDROID_SDK_ROOT=C:\Users\peter\AppData\Local\Android\sdk (recommended setting)
3ANDROID_HOME=undefined (DEPRECATED)
4Using Android SDK: C:\Users\peter\AppData\Local\Android\sdk
5

I also have the folder C:\Users\peter\.android an C:\Users\peter\.gradle

I upgraded Android Studio,dowloaded SDK's etc, and started a new project after reading elsewhere this may update the build tools. This did make a difference, as originally the error reported installed version was 29.0.2 and now it is 30.0.2, but something is looking for 30.0.3.

The version 30.0.3 is coming from the file platforms\android\cdv-gradle-config.json, and I have the following folders in `C:\Users\peter\AppData\Local\Android\sdk\build-tools..

enter image description here

I cannot see how to get 30.0.3, when I look at https://developer.android.com/studio/releases/build-tools#groovy I don't see this version

Why might this config have this version, or where I can get this version of the build tools?

ANSWER

Answered 2021-Nov-18 at 06:30

Today, I could finally install version 30.0.3.

In Android Studio, I could see and install it from here...

enter image description here

After this, and then also having to remove the whitelist plugin (it is not required any more), I could get it to build.

Only hassle now is it outs to a .aab and not an .apk so side load testing now harder. But the main issue, the building is now working (on Windows PC).. Now hopefully can do the same on the Mac.

Source https://stackoverflow.com/questions/70002327

QUESTION

How to make Kotlin Multiplatform work with Android Studio's project view?

Asked 2022-Jan-28 at 06:57

I am trying to build a template of a Multiplatform library module in Android studio that can interoperate seamlessly with other normal Android library and application modules. I've found it's easy enough to make a Multiplatform Android project technically work in terms of compiling, running and publishing artefacts, but one problem I can't seem to solve is getting the source sets to show correctly in the Android project files pane view.

So you can see in the Project view here, the sources are divided into android, native and common directories and their respective test directories, for a total of six source directories:

Project File View

In the Android Project view this is rendered by build targets instead of source file directories, so that this 'typing-sdk' module example has total of 10 different sub-modules. And you'll notice androidMain and androidTest are not among them: instead of being rendered as submodules, their sources fall under an inline kotlin directory instead; you can see the main and test com.demo.typing packages respectively.

Android Project View

It is a little annoying that every single build target gets its own submodule, when in practice, one will virtually never actually need to use some of these, like 'iosArm64Test' for example. Nevertheless, I can live with redundant submodules. The central problem here is that each of these submodules are populated with the wrong source files.

So whereas in the file structure, both the common and native sets have their own source files, as you can seen here:

Expanded Project File View

In the Android Project View, every single submodule contains the Android sources!?

Expanded Android Project View

Either this is a bug in how Android Studio interoperates with the Kotlin Multiplatform Gradle Plugin, or there's something wrong with the Gradle build file I have written, which is this (using Gradle 7.1):

1plugins {
2    id 'org.jetbrains.kotlin.multiplatform' version '1.6.10'
3    id 'com.android.library' version '7.0.4'
4}
5
6allprojects {
7    group = 'typing'
8    version = '1.0'
9    sourceCompatibility = '1.8'
10
11    repositories {
12        mavenCentral()
13        google()
14    }
15}
16
17kotlin {
18    android()
19    ios()
20
21    sourceSets {
22        commonMain
23        commonTest
24        androidMain {
25            dependsOn(commonMain)
26        }
27        androidAndroidTestRelease
28        androidTest {
29            dependsOn(commonTest)
30            dependsOn(androidAndroidTestRelease)
31        }
32        nativeMain {
33            dependsOn(commonMain)
34        }
35        nativeTest {
36            dependsOn(commonTest)
37        }
38        iosMain {
39            dependsOn(nativeMain)
40            iosX64Main.dependsOn(it)
41            iosArm64Main.dependsOn(it)
42        }
43        iosTest {
44            dependsOn(nativeTest)
45            iosX64Test.dependsOn(it)
46            iosArm64Test.dependsOn(it)
47        }
48    }
49}
50
51android {
52    compileSdk 31
53    defaultConfig {
54        minSdk 23
55        targetSdk 30
56    }
57}
58

I have noticed most of the source examples already out there are using Kotlin DSL, which is preferable, but circumstances are forcing me to use Groovy here. On another project I have that is Kotlin DSL, using earlier versions of the Gradle (7.0.2) Android Gradle Plugin (7.0.2) and Kotlin (1.5.20), the Android project view is rendered differently, and though still quite defective, it's not so disastrously wrong as to have Android sources listed under every single build target module. In the Android block on that project you have a second definition of the sourcesets to the com.android.library plugin:

1plugins {
2    id 'org.jetbrains.kotlin.multiplatform' version '1.6.10'
3    id 'com.android.library' version '7.0.4'
4}
5
6allprojects {
7    group = 'typing'
8    version = '1.0'
9    sourceCompatibility = '1.8'
10
11    repositories {
12        mavenCentral()
13        google()
14    }
15}
16
17kotlin {
18    android()
19    ios()
20
21    sourceSets {
22        commonMain
23        commonTest
24        androidMain {
25            dependsOn(commonMain)
26        }
27        androidAndroidTestRelease
28        androidTest {
29            dependsOn(commonTest)
30            dependsOn(androidAndroidTestRelease)
31        }
32        nativeMain {
33            dependsOn(commonMain)
34        }
35        nativeTest {
36            dependsOn(commonTest)
37        }
38        iosMain {
39            dependsOn(nativeMain)
40            iosX64Main.dependsOn(it)
41            iosArm64Main.dependsOn(it)
42        }
43        iosTest {
44            dependsOn(nativeTest)
45            iosX64Test.dependsOn(it)
46            iosArm64Test.dependsOn(it)
47        }
48    }
49}
50
51android {
52    compileSdk 31
53    defaultConfig {
54        minSdk 23
55        targetSdk 30
56    }
57}
58android {
59    compileSdk = 31
60    defaultConfig {
61        minSdk = 23
62        targetSdk = 30
63
64        consumerProguardFiles("proguard-rules.pro")
65    }
66    sourceSets.all {
67        java.srcDirs(file("src/android${name.capitalize()}/kotlin"))
68        res.srcDirs(file("src/android${name.capitalize()}/res"))
69        resources.srcDirs(file("src/android${name.capitalize()}/resources"))
70        manifest.srcFile(file("src/android${name.capitalize()}/AndroidManifest.xml"))
71    }
72    compileOptions {
73        sourceCompatibility = JavaVersion.VERSION_1_8
74        targetCompatibility = JavaVersion.VERSION_1_8
75    }
76}
77

I don't know how to directly translate this into Groovy, but following the Android documentation, one can put something like this:

1plugins {
2    id 'org.jetbrains.kotlin.multiplatform' version '1.6.10'
3    id 'com.android.library' version '7.0.4'
4}
5
6allprojects {
7    group = 'typing'
8    version = '1.0'
9    sourceCompatibility = '1.8'
10
11    repositories {
12        mavenCentral()
13        google()
14    }
15}
16
17kotlin {
18    android()
19    ios()
20
21    sourceSets {
22        commonMain
23        commonTest
24        androidMain {
25            dependsOn(commonMain)
26        }
27        androidAndroidTestRelease
28        androidTest {
29            dependsOn(commonTest)
30            dependsOn(androidAndroidTestRelease)
31        }
32        nativeMain {
33            dependsOn(commonMain)
34        }
35        nativeTest {
36            dependsOn(commonTest)
37        }
38        iosMain {
39            dependsOn(nativeMain)
40            iosX64Main.dependsOn(it)
41            iosArm64Main.dependsOn(it)
42        }
43        iosTest {
44            dependsOn(nativeTest)
45            iosX64Test.dependsOn(it)
46            iosArm64Test.dependsOn(it)
47        }
48    }
49}
50
51android {
52    compileSdk 31
53    defaultConfig {
54        minSdk 23
55        targetSdk 30
56    }
57}
58android {
59    compileSdk = 31
60    defaultConfig {
61        minSdk = 23
62        targetSdk = 30
63
64        consumerProguardFiles("proguard-rules.pro")
65    }
66    sourceSets.all {
67        java.srcDirs(file("src/android${name.capitalize()}/kotlin"))
68        res.srcDirs(file("src/android${name.capitalize()}/res"))
69        resources.srcDirs(file("src/android${name.capitalize()}/resources"))
70        manifest.srcFile(file("src/android${name.capitalize()}/AndroidManifest.xml"))
71    }
72    compileOptions {
73        sourceCompatibility = JavaVersion.VERSION_1_8
74        targetCompatibility = JavaVersion.VERSION_1_8
75    }
76}
77android {
78    compileSdk 31
79    defaultConfig {
80        minSdk 23
81        targetSdk 30
82    }
83    sourceSets {
84        main {
85            java.srcDirs = ['src/androidMain/kotlin']
86            manifest.srcFile 'src/androidMain/AndroidManifest.xml'
87        }
88        test {
89            java.srcDirs = ['src/androidTest/kotlin']
90        }
91        androidTest {
92            setRoot 'src/androidTest/kotlin'
93        }
94    }
95}
96

Unfortunately this doesn't solve the problem. If nobody can show me workable Gradle scripts that don't create hideous and broken source file views in Android Studio, I will submit this as a bug to JetBrains.

ANSWER

Answered 2022-Jan-28 at 06:57

IntellIJ is the recommended IDE to use when it comes to Multiplatform development.

Android Studio is for more Android Specific things, I don't think Android project view is something JetBrains wants to support, maybe there will be a Kotlin Multiplatform Project View at some point, but not at the moment.

(If you open a Spring, NodeJS, iOS or any other type of project the Android Project View will similarly seem broken)

Source https://stackoverflow.com/questions/70882746

QUESTION

Jenkins log4j vulnerability testing from pipeline job

Asked 2021-Dec-27 at 20:39

I am trying to make sure my Jenkins instance is not exploitable with the latest log4j exploit.

I have a pipeline script that runs, I tried following this instruction :

https://community.jenkins.io/t/apache-log4j-2-vulnerability-cve-2021-44228/990

This is one of my stages of my pipeline script:

1stage('Building image aaa') {
2      steps{
3        script {
4          sh "echo executing"
5          org.apache.logging.log4j.core.lookup.JndiLookup.class.protectionDomain.codeSource
6          sh "docker build --build-arg SCRIPT_ENVIRONMENT=staging -t $IMAGE_REPO_NAME:$IMAGE_TAG ."
7        }
8      }
9    }
10

But I get a different error than what's described here and I'm unsure if I'm checking this correctly. This is the error:

1stage('Building image aaa') {
2      steps{
3        script {
4          sh "echo executing"
5          org.apache.logging.log4j.core.lookup.JndiLookup.class.protectionDomain.codeSource
6          sh "docker build --build-arg SCRIPT_ENVIRONMENT=staging -t $IMAGE_REPO_NAME:$IMAGE_TAG ."
7        }
8      }
9    }
10groovy.lang.MissingPropertyException: No such property: org for class: groovy.lang.Binding
11    at groovy.lang.Binding.getVariable(Binding.java:63)
12    at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onGetProperty(SandboxInterceptor.java:271)
13    at org.kohsuke.groovy.sandbox.impl.Checker$7.call(Checker.java:353)
14    at org.kohsuke.groovy.sandbox.impl.Checker.checkedGetProperty(Checker.java:357)
15    at org.kohsuke.groovy.sandbox.impl.Checker.checkedGetProperty(Checker.java:333)
16    at org.kohsuke.groovy.sandbox.impl.Checker.checkedGetProperty(Checker.java:333)
17    at org.kohsuke.groovy.sandbox.impl.Checker.checkedGetProperty(Checker.java:333)
18    at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.getProperty(SandboxInvoker.java:29)
19    at com.cloudbees.groovy.cps.impl.PropertyAccessBlock.rawGet(PropertyAccessBlock.java:20)
20    at WorkflowScript.run(WorkflowScript:31)
21    at ___cps.transform___(Native Method)
22    at com.cloudbees.groovy.cps.impl.PropertyishBlock$ContinuationImpl.get(PropertyishBlock.java:74)
23    at com.cloudbees.groovy.cps.LValueBlock$GetAdapter.receive(LValueBlock.java:30)
24....etc
25

ANSWER

Answered 2021-Dec-27 at 20:39

I don't think a class name would be directly interpreted as a groovy codeSource argument in a declarative pipeline (as opposed to a scripted one)

Try the approach of "How to import a file of classes in a Jenkins Pipeline?", with:

1stage('Building image aaa') {
2      steps{
3        script {
4          sh "echo executing"
5          org.apache.logging.log4j.core.lookup.JndiLookup.class.protectionDomain.codeSource
6          sh "docker build --build-arg SCRIPT_ENVIRONMENT=staging -t $IMAGE_REPO_NAME:$IMAGE_TAG ."
7        }
8      }
9    }
10groovy.lang.MissingPropertyException: No such property: org for class: groovy.lang.Binding
11    at groovy.lang.Binding.getVariable(Binding.java:63)
12    at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onGetProperty(SandboxInterceptor.java:271)
13    at org.kohsuke.groovy.sandbox.impl.Checker$7.call(Checker.java:353)
14    at org.kohsuke.groovy.sandbox.impl.Checker.checkedGetProperty(Checker.java:357)
15    at org.kohsuke.groovy.sandbox.impl.Checker.checkedGetProperty(Checker.java:333)
16    at org.kohsuke.groovy.sandbox.impl.Checker.checkedGetProperty(Checker.java:333)
17    at org.kohsuke.groovy.sandbox.impl.Checker.checkedGetProperty(Checker.java:333)
18    at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.getProperty(SandboxInvoker.java:29)
19    at com.cloudbees.groovy.cps.impl.PropertyAccessBlock.rawGet(PropertyAccessBlock.java:20)
20    at WorkflowScript.run(WorkflowScript:31)
21    at ___cps.transform___(Native Method)
22    at com.cloudbees.groovy.cps.impl.PropertyishBlock$ContinuationImpl.get(PropertyishBlock.java:74)
23    at com.cloudbees.groovy.cps.LValueBlock$GetAdapter.receive(LValueBlock.java:30)
24....etc
25node{
26    def cl = load 'Classes.groovy'
27    def a = cl.getProperty("org.apache.logging.log4j.core.lookup.JndiLookup").protectionDomain.codeSource
28    ...
29}
30

Note that getCLassLoader() is by default disallowed, and should require from an Jenkins administrator In-process Script Approval.

Source https://stackoverflow.com/questions/70454734

QUESTION

Why is "continuous-integration/jenkins/pr-merge" not being triggered by GitHub on a pull request?

Asked 2021-Dec-08 at 20:18

In GitHub Enterprise, we have Project A under Organization A. When I submit a PR (pull request) to Project A, the continuous-integration/jenkins/pr-merge is triggered which runs a Jenkins pipeline to build the code and perform unit tests. This allows us to prevent the PR from being merged into master if the unit tests fail.

For example, this is what I see on a PR for Project A in GitHub that includes a broken unit test: enter image description here

Now I am trying to configure Project B under Organization B to behave the same way. However, it is not working. This is what I see on a PR for Project B in GitHub that includes a broken unit test:

enter image description here

Notice that Project B's PR did not kick off the continuous-integration/jenkins/pr-merge.

Configuration of Project A and Project B

GitHub -> Settings -> Branches -> Branch protection rules

Project A in GitHub has a branch protection rule for master with only one setting enabled:

  • Require pull request reviews before merging

Interestingly, the "Require status checks to pass before merging" setting is not enabled. Out of curiosity, I enabled it (without saving it) and noticed that "continuous-integration/jenkins/pr-merge" showed up below it as an option.

I configured Project B to have the exact same branch protection rule for master with only "Require pull request reviews before merging" enabled. Out of curiosity, I enabled "Require status checks to pass before merging" (without saving it) and it doesn't even show continuous-integration/jenkins/pr-merge as an option. It just says "No status checks found. Sorry, we couldn’t find any status checks in the last week for this repository."

GitHub -> Settings -> Hooks -> Webhooks

Project A in GitHub has a webhook configured with:

  • Payload URL https://jenkins.mycompany.com/github-webhook/
  • Content type application/json
  • Let me select individual events: Pull requests, Pushes, Repositories are checked
  • Active: checked

I created a webhook for Project B with the exact same settings. After I submitted a PR for Project B, I see a couple of items under "Recent Deliveries" for Project B's webhook with green checkmarks and "200" response codes, so I think it is configured correctly.

CloudBees Jenkins Enterprise

In Jenkins Enterprise, Project A's pipeline is of type "GitHub Organization" and has the following settings:

  • API endpoint: kubernetes-cbs-automation (https://git.mycompany.com/api/v3)
  • Credentials: [credentials specific to Project A]
  • Owner: [Project A's GitHub organization]
  • Behaviors: Repositories: Filter by name (with regular expression): Regular expression: [name of Project A's GitHub repo]
  • Behaviors: Within repository: Discover pull requests from origin: Strategy: Merging the pull request with the current target branch revision
  • Project Recognizers: Pipeline Jenkinsfile: Script Path: ci-cd/jenkins/ProjectA-pipeline.groovy
  • Property strategy: All branches get the same properties
  • Scan Organization Triggers: "Periodically if not otherwise run" checked: Interval: 1 day
  • Orphaned Item Strategy: "Discard old items" checked
  • Child Orphaned Item Strategy: Strategy: Inherited
  • Child Scan Triggers: "Periodically if not otherwise run" checked: Interval: 1 day
  • Automatic branch project triggering: Branch names to build automatically: .*

I created an item under Project B in Jenkins Enterprise of type "GitHub Organization" with the same settings (except any settings specific to Project A were replaced with the appropriate Project B specific settings).

What is wrong/missing?

Given that GitHub PRs for Project B are failing to launch the continuous-integration/jenkins/pr-merge, it seems like there is some configuration that I am missing. Unfortunately, our GitHub/Jenkins admins have not been able to figure out what is wrong.

UPDATE

We have confirmed that Project B is actually launching a build on the Jenkins agent when a PR is submitted. The problem is that GitHub is not showing the continuous-integration/jenkins/pr-merge on the web page for the PR. We need that so the PR can be blocked if the build fails, and also so that we can quickly see what went wrong.

ANSWER

Answered 2021-Dec-08 at 20:18

Posting as answer the resolution we got in the comments.

The issue was that the user who's token was used in Jenkins did not have the right level of access to post status checks on the repository.

Differences between the Orgs and Projects

  • OrgA/ProjectA - the user is a Member of the organisation (OrgA) also added in the Collaborators section of the repo with Read access, as well as member of a Team with Write access on the repo itself (ProjectA).
  • OrgB/ProjectB - the user was a Member of the organisation (OrgB) and also in the Collaborators section on the repo itself (ProjectB) but with Read access.

This caused the issue on projectB status checks not being populated with Jenkins' information from the builds:
continuous-integration/jenkins/pr-merge missing from the status checks of GitHub repository.

Summary:
When setting up a connection between GitHub and Jenkins we need to provide the user holder of the token with the required access.

In this case we want to update the github status which needs Write access level:

github permission level for status checks

The token of the user should have scope repo:status

Source https://stackoverflow.com/questions/69452489

QUESTION

How to bring list of jenkins nodes to Active choice parameter and present only those for the current logged in user

Asked 2021-Nov-08 at 21:30

I have Jenkins job with active choice parameter with the name Computer. Which groovy script I should write to bring me all the Nodes names, and present only the one for the current logged in user? All nodes are with the label Desktop. I tried the below but it doesn't work:

1import hudson.slaves.DumbSlave
2
3def users = []
4for (DumbSlave it : Hudson.instance.getSlaves()) {
5  if(it.getLabelString().contains("Desktop")) {
6    def currAgent = it?.computer?.name
7    if(currAgent != null) {
8      users.add(currAgent)
9     }
10  }
11}
12
13return users
14

Update (full answer with logged-on user, based on the below answer):

1import hudson.slaves.DumbSlave
2
3def users = []
4for (DumbSlave it : Hudson.instance.getSlaves()) {
5  if(it.getLabelString().contains("Desktop")) {
6    def currAgent = it?.computer?.name
7    if(currAgent != null) {
8      users.add(currAgent)
9     }
10  }
11}
12
13return users
14import jenkins.model.*
15import hudson.model.User
16
17
18def users = []
19Jenkins.instance.nodes.each { node ->
20  if(node.labelString.contains("Desktop")) {
21    def currAgent = node?.computer
22    def currAgentName = node?.computer?.name
23    if(currAgentName != null) {
24      def user = currAgent.systemProperties['user.name']?.toLowerCase()
25      if (!users.contains(user) && user==User.current().toString()){
26        users.add(currAgentName)
27      }
28    }
29  }
30}
31
32return users
33

ANSWER

Answered 2021-Nov-08 at 21:30

Try this:

1import hudson.slaves.DumbSlave
2
3def users = []
4for (DumbSlave it : Hudson.instance.getSlaves()) {
5  if(it.getLabelString().contains("Desktop")) {
6    def currAgent = it?.computer?.name
7    if(currAgent != null) {
8      users.add(currAgent)
9     }
10  }
11}
12
13return users
14import jenkins.model.*
15import hudson.model.User
16
17
18def users = []
19Jenkins.instance.nodes.each { node ->
20  if(node.labelString.contains("Desktop")) {
21    def currAgent = node?.computer
22    def currAgentName = node?.computer?.name
23    if(currAgentName != null) {
24      def user = currAgent.systemProperties['user.name']?.toLowerCase()
25      if (!users.contains(user) && user==User.current().toString()){
26        users.add(currAgentName)
27      }
28    }
29  }
30}
31
32return users
33import jenkins.model.*
34
35def users = []
36Jenkins.instance.nodes.each { node ->
37    if(node.labelString.contains("Desktop")) {
38        def currAgent = node?.computer?.name
39        if(currAgent != null) {
40            users.add(currAgent)
41        }
42    }
43 }
44
45 return users
46

Or make it Groovyer:

1import hudson.slaves.DumbSlave
2
3def users = []
4for (DumbSlave it : Hudson.instance.getSlaves()) {
5  if(it.getLabelString().contains("Desktop")) {
6    def currAgent = it?.computer?.name
7    if(currAgent != null) {
8      users.add(currAgent)
9     }
10  }
11}
12
13return users
14import jenkins.model.*
15import hudson.model.User
16
17
18def users = []
19Jenkins.instance.nodes.each { node ->
20  if(node.labelString.contains("Desktop")) {
21    def currAgent = node?.computer
22    def currAgentName = node?.computer?.name
23    if(currAgentName != null) {
24      def user = currAgent.systemProperties['user.name']?.toLowerCase()
25      if (!users.contains(user) && user==User.current().toString()){
26        users.add(currAgentName)
27      }
28    }
29  }
30}
31
32return users
33import jenkins.model.*
34
35def users = []
36Jenkins.instance.nodes.each { node ->
37    if(node.labelString.contains("Desktop")) {
38        def currAgent = node?.computer?.name
39        if(currAgent != null) {
40            users.add(currAgent)
41        }
42    }
43 }
44
45 return users
46import jenkins.model.*
47
48return Jenkins.instance.nodes.findAll { node ->
49   node.labelString.contains("Desktop") &&
50     node.computer.systemProperties["user.name"] == User.current().toString()
51                                      }.collect { node ->
52                                          node?.computer?.name }
53

Source https://stackoverflow.com/questions/69868185

QUESTION

Kafka integration tests in Gradle runs into GitHub Actions

Asked 2021-Nov-03 at 19:11

We've been moving our applications from CircleCI to GitHub Actions in our company and we got stuck with a strange situation.

There has been no change to the project's code, but our kafka integration tests started to fail in GH Actions machines. Everything works fine in CircleCI and locally (MacOS and Fedora linux machines).

Both CircleCI and GH Actions machines are running Ubuntu (tested versions were 18.04 and 20.04). MacOS was not tested in GH Actions as it doesn't have Docker in it.

Here are the docker-compose and workflow files used by the build and integration tests:

  • docker-compose.yml
1version: '2.1'
2
3services:
4  postgres:
5    container_name: listings-postgres
6    image: postgres:10-alpine
7    mem_limit: 500m
8    networks:
9      - listings-stack
10    ports:
11      - "5432:5432"
12    environment:
13      POSTGRES_DB: listings
14      POSTGRES_PASSWORD: listings
15      POSTGRES_USER: listings
16      PGUSER: listings
17    healthcheck:
18      test: ["CMD", "pg_isready"]
19      interval: 1s
20      timeout: 3s
21      retries: 30
22
23  listings-zookeeper:
24    container_name: listings-zookeeper
25    image: confluentinc/cp-zookeeper:6.2.0
26    environment:
27      ZOOKEEPER_CLIENT_PORT: 2181
28      ZOOKEEPER_TICK_TIME: 2000
29    networks:
30      - listings-stack
31    ports:
32      - "2181:2181"
33    healthcheck:
34      test: nc -z localhost 2181 || exit -1
35      interval: 10s
36      timeout: 5s
37      retries: 10
38
39  listings-kafka:
40    container_name: listings-kafka
41    image: confluentinc/cp-kafka:6.2.0
42    depends_on:
43      listings-zookeeper:
44        condition: service_healthy
45    environment:
46      KAFKA_BROKER_ID: 1
47      KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://listings-kafka:9092,PLAINTEXT_HOST://localhost:29092
48      KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT
49      KAFKA_INTER_BROKER_LISTENER_NAME: PLAINTEXT
50      KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
51      KAFKA_ZOOKEEPER_CONNECT: listings-zookeeper:2181
52    volumes:
53      - /var/run/docker.sock:/var/run/docker.sock
54    networks:
55      - listings-stack
56    ports:
57      - "29092:29092"
58    healthcheck:
59      test: kafka-topics --bootstrap-server 127.0.0.1:9092 --list
60      interval: 10s
61      timeout: 10s
62      retries: 50
63
64networks: {listings-stack: {}}
65
  • build.yml
1version: '2.1'
2
3services:
4  postgres:
5    container_name: listings-postgres
6    image: postgres:10-alpine
7    mem_limit: 500m
8    networks:
9      - listings-stack
10    ports:
11      - "5432:5432"
12    environment:
13      POSTGRES_DB: listings
14      POSTGRES_PASSWORD: listings
15      POSTGRES_USER: listings
16      PGUSER: listings
17    healthcheck:
18      test: ["CMD", "pg_isready"]
19      interval: 1s
20      timeout: 3s
21      retries: 30
22
23  listings-zookeeper:
24    container_name: listings-zookeeper
25    image: confluentinc/cp-zookeeper:6.2.0
26    environment:
27      ZOOKEEPER_CLIENT_PORT: 2181
28      ZOOKEEPER_TICK_TIME: 2000
29    networks:
30      - listings-stack
31    ports:
32      - "2181:2181"
33    healthcheck:
34      test: nc -z localhost 2181 || exit -1
35      interval: 10s
36      timeout: 5s
37      retries: 10
38
39  listings-kafka:
40    container_name: listings-kafka
41    image: confluentinc/cp-kafka:6.2.0
42    depends_on:
43      listings-zookeeper:
44        condition: service_healthy
45    environment:
46      KAFKA_BROKER_ID: 1
47      KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://listings-kafka:9092,PLAINTEXT_HOST://localhost:29092
48      KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT
49      KAFKA_INTER_BROKER_LISTENER_NAME: PLAINTEXT
50      KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
51      KAFKA_ZOOKEEPER_CONNECT: listings-zookeeper:2181
52    volumes:
53      - /var/run/docker.sock:/var/run/docker.sock
54    networks:
55      - listings-stack
56    ports:
57      - "29092:29092"
58    healthcheck:
59      test: kafka-topics --bootstrap-server 127.0.0.1:9092 --list
60      interval: 10s
61      timeout: 10s
62      retries: 50
63
64networks: {listings-stack: {}}
65name: Build
66
67on: [ pull_request ]
68
69env:
70  AWS_ACCESS_KEY_ID: ${{ secrets.TUNNEL_AWS_ACCESS_KEY_ID }}
71  AWS_SECRET_ACCESS_KEY: ${{ secrets.TUNNEL_AWS_SECRET_ACCESS_KEY }}
72  AWS_DEFAULT_REGION: 'us-east-1'
73  CIRCLECI_KEY_TUNNEL: ${{ secrets.ID_RSA_CIRCLECI_TUNNEL }}
74
75jobs:
76  build:
77    name: Listings-API Build
78    runs-on: [ self-hosted, zap ]
79
80    steps:
81      - uses: actions/checkout@v2
82        with:
83          token: ${{ secrets.GH_OLXBR_PAT }}
84          submodules: recursive
85          path: ./repo
86          fetch-depth: 0
87
88      - name: Set up JDK 11
89        uses: actions/setup-java@v2
90        with:
91          distribution: 'adopt'
92          java-version: '11'
93          architecture: x64
94          cache: 'gradle'
95
96      - name: Docker up
97        working-directory: ./repo
98        run: docker-compose up -d
99
100      - name: Build with Gradle
101        working-directory: ./repo
102        run: ./gradlew build -Dhttps.protocols=TLSv1,TLSv1.1,TLSv1.2 -x integrationTest
103
104      - name: Integration tests with Gradle
105        working-directory: ./repo
106        run: ./gradlew integrationTest -Dhttps.protocols=TLSv1,TLSv1.1,TLSv1.2
107
108      - name: Sonarqube
109        working-directory: ./repo
110        env:
111          GITHUB_TOKEN: ${{ secrets.GH_OLXBR_PAT }}
112          SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
113        run: ./gradlew sonarqube --info -Dhttps.protocols=TLSv1,TLSv1.1,TLSv1.2
114
115      - name: Docker down
116        if: always()
117        working-directory: ./repo
118        run: docker-compose down --remove-orphans
119
120      - name: Cleanup Gradle Cache
121        # Remove some files from the Gradle cache, so they aren't cached by GitHub Actions.
122        # Restoring these files from a GitHub Actions cache might cause problems for future builds.
123        run: |
124          rm -f ${{ env.HOME }}/.gradle/caches/modules-2/modules-2.lock
125          rm -f ${{ env.HOME }}/.gradle/caches/modules-2/gc.properties
126
127

The integration tests are written using the Spock framework and the part where the errors occur are these:

1version: '2.1'
2
3services:
4  postgres:
5    container_name: listings-postgres
6    image: postgres:10-alpine
7    mem_limit: 500m
8    networks:
9      - listings-stack
10    ports:
11      - "5432:5432"
12    environment:
13      POSTGRES_DB: listings
14      POSTGRES_PASSWORD: listings
15      POSTGRES_USER: listings
16      PGUSER: listings
17    healthcheck:
18      test: ["CMD", "pg_isready"]
19      interval: 1s
20      timeout: 3s
21      retries: 30
22
23  listings-zookeeper:
24    container_name: listings-zookeeper
25    image: confluentinc/cp-zookeeper:6.2.0
26    environment:
27      ZOOKEEPER_CLIENT_PORT: 2181
28      ZOOKEEPER_TICK_TIME: 2000
29    networks:
30      - listings-stack
31    ports:
32      - "2181:2181"
33    healthcheck:
34      test: nc -z localhost 2181 || exit -1
35      interval: 10s
36      timeout: 5s
37      retries: 10
38
39  listings-kafka:
40    container_name: listings-kafka
41    image: confluentinc/cp-kafka:6.2.0
42    depends_on:
43      listings-zookeeper:
44        condition: service_healthy
45    environment:
46      KAFKA_BROKER_ID: 1
47      KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://listings-kafka:9092,PLAINTEXT_HOST://localhost:29092
48      KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT
49      KAFKA_INTER_BROKER_LISTENER_NAME: PLAINTEXT
50      KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
51      KAFKA_ZOOKEEPER_CONNECT: listings-zookeeper:2181
52    volumes:
53      - /var/run/docker.sock:/var/run/docker.sock
54    networks:
55      - listings-stack
56    ports:
57      - "29092:29092"
58    healthcheck:
59      test: kafka-topics --bootstrap-server 127.0.0.1:9092 --list
60      interval: 10s
61      timeout: 10s
62      retries: 50
63
64networks: {listings-stack: {}}
65name: Build
66
67on: [ pull_request ]
68
69env:
70  AWS_ACCESS_KEY_ID: ${{ secrets.TUNNEL_AWS_ACCESS_KEY_ID }}
71  AWS_SECRET_ACCESS_KEY: ${{ secrets.TUNNEL_AWS_SECRET_ACCESS_KEY }}
72  AWS_DEFAULT_REGION: 'us-east-1'
73  CIRCLECI_KEY_TUNNEL: ${{ secrets.ID_RSA_CIRCLECI_TUNNEL }}
74
75jobs:
76  build:
77    name: Listings-API Build
78    runs-on: [ self-hosted, zap ]
79
80    steps:
81      - uses: actions/checkout@v2
82        with:
83          token: ${{ secrets.GH_OLXBR_PAT }}
84          submodules: recursive
85          path: ./repo
86          fetch-depth: 0
87
88      - name: Set up JDK 11
89        uses: actions/setup-java@v2
90        with:
91          distribution: 'adopt'
92          java-version: '11'
93          architecture: x64
94          cache: 'gradle'
95
96      - name: Docker up
97        working-directory: ./repo
98        run: docker-compose up -d
99
100      - name: Build with Gradle
101        working-directory: ./repo
102        run: ./gradlew build -Dhttps.protocols=TLSv1,TLSv1.1,TLSv1.2 -x integrationTest
103
104      - name: Integration tests with Gradle
105        working-directory: ./repo
106        run: ./gradlew integrationTest -Dhttps.protocols=TLSv1,TLSv1.1,TLSv1.2
107
108      - name: Sonarqube
109        working-directory: ./repo
110        env:
111          GITHUB_TOKEN: ${{ secrets.GH_OLXBR_PAT }}
112          SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
113        run: ./gradlew sonarqube --info -Dhttps.protocols=TLSv1,TLSv1.1,TLSv1.2
114
115      - name: Docker down
116        if: always()
117        working-directory: ./repo
118        run: docker-compose down --remove-orphans
119
120      - name: Cleanup Gradle Cache
121        # Remove some files from the Gradle cache, so they aren't cached by GitHub Actions.
122        # Restoring these files from a GitHub Actions cache might cause problems for future builds.
123        run: |
124          rm -f ${{ env.HOME }}/.gradle/caches/modules-2/modules-2.lock
125          rm -f ${{ env.HOME }}/.gradle/caches/modules-2/gc.properties
126
127  boolean compareRecordSend(String topicName, int expected) {
128    def condition = new PollingConditions()
129    condition.within(kafkaProperties.listener.pollTimeout.getSeconds() * 5) {
130      assert expected == getRecordSendTotal(topicName)
131    }
132    return true
133  }
134
135  int getRecordSendTotal(String topicName) {
136    kafkaTemplate.flush()
137    return kafkaTemplate.metrics().find {
138      it.key.name() == "record-send-total" && it.key.tags().get("topic") == topicName
139    }?.value?.metricValue() ?: 0
140  }
141

The error we're getting is:

1version: '2.1'
2
3services:
4  postgres:
5    container_name: listings-postgres
6    image: postgres:10-alpine
7    mem_limit: 500m
8    networks:
9      - listings-stack
10    ports:
11      - "5432:5432"
12    environment:
13      POSTGRES_DB: listings
14      POSTGRES_PASSWORD: listings
15      POSTGRES_USER: listings
16      PGUSER: listings
17    healthcheck:
18      test: ["CMD", "pg_isready"]
19      interval: 1s
20      timeout: 3s
21      retries: 30
22
23  listings-zookeeper:
24    container_name: listings-zookeeper
25    image: confluentinc/cp-zookeeper:6.2.0
26    environment:
27      ZOOKEEPER_CLIENT_PORT: 2181
28      ZOOKEEPER_TICK_TIME: 2000
29    networks:
30      - listings-stack
31    ports:
32      - "2181:2181"
33    healthcheck:
34      test: nc -z localhost 2181 || exit -1
35      interval: 10s
36      timeout: 5s
37      retries: 10
38
39  listings-kafka:
40    container_name: listings-kafka
41    image: confluentinc/cp-kafka:6.2.0
42    depends_on:
43      listings-zookeeper:
44        condition: service_healthy
45    environment:
46      KAFKA_BROKER_ID: 1
47      KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://listings-kafka:9092,PLAINTEXT_HOST://localhost:29092
48      KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT
49      KAFKA_INTER_BROKER_LISTENER_NAME: PLAINTEXT
50      KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
51      KAFKA_ZOOKEEPER_CONNECT: listings-zookeeper:2181
52    volumes:
53      - /var/run/docker.sock:/var/run/docker.sock
54    networks:
55      - listings-stack
56    ports:
57      - "29092:29092"
58    healthcheck:
59      test: kafka-topics --bootstrap-server 127.0.0.1:9092 --list
60      interval: 10s
61      timeout: 10s
62      retries: 50
63
64networks: {listings-stack: {}}
65name: Build
66
67on: [ pull_request ]
68
69env:
70  AWS_ACCESS_KEY_ID: ${{ secrets.TUNNEL_AWS_ACCESS_KEY_ID }}
71  AWS_SECRET_ACCESS_KEY: ${{ secrets.TUNNEL_AWS_SECRET_ACCESS_KEY }}
72  AWS_DEFAULT_REGION: 'us-east-1'
73  CIRCLECI_KEY_TUNNEL: ${{ secrets.ID_RSA_CIRCLECI_TUNNEL }}
74
75jobs:
76  build:
77    name: Listings-API Build
78    runs-on: [ self-hosted, zap ]
79
80    steps:
81      - uses: actions/checkout@v2
82        with:
83          token: ${{ secrets.GH_OLXBR_PAT }}
84          submodules: recursive
85          path: ./repo
86          fetch-depth: 0
87
88      - name: Set up JDK 11
89        uses: actions/setup-java@v2
90        with:
91          distribution: 'adopt'
92          java-version: '11'
93          architecture: x64
94          cache: 'gradle'
95
96      - name: Docker up
97        working-directory: ./repo
98        run: docker-compose up -d
99
100      - name: Build with Gradle
101        working-directory: ./repo
102        run: ./gradlew build -Dhttps.protocols=TLSv1,TLSv1.1,TLSv1.2 -x integrationTest
103
104      - name: Integration tests with Gradle
105        working-directory: ./repo
106        run: ./gradlew integrationTest -Dhttps.protocols=TLSv1,TLSv1.1,TLSv1.2
107
108      - name: Sonarqube
109        working-directory: ./repo
110        env:
111          GITHUB_TOKEN: ${{ secrets.GH_OLXBR_PAT }}
112          SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
113        run: ./gradlew sonarqube --info -Dhttps.protocols=TLSv1,TLSv1.1,TLSv1.2
114
115      - name: Docker down
116        if: always()
117        working-directory: ./repo
118        run: docker-compose down --remove-orphans
119
120      - name: Cleanup Gradle Cache
121        # Remove some files from the Gradle cache, so they aren't cached by GitHub Actions.
122        # Restoring these files from a GitHub Actions cache might cause problems for future builds.
123        run: |
124          rm -f ${{ env.HOME }}/.gradle/caches/modules-2/modules-2.lock
125          rm -f ${{ env.HOME }}/.gradle/caches/modules-2/gc.properties
126
127  boolean compareRecordSend(String topicName, int expected) {
128    def condition = new PollingConditions()
129    condition.within(kafkaProperties.listener.pollTimeout.getSeconds() * 5) {
130      assert expected == getRecordSendTotal(topicName)
131    }
132    return true
133  }
134
135  int getRecordSendTotal(String topicName) {
136    kafkaTemplate.flush()
137    return kafkaTemplate.metrics().find {
138      it.key.name() == "record-send-total" && it.key.tags().get("topic") == topicName
139    }?.value?.metricValue() ?: 0
140  }
141Condition not satisfied after 50.00 seconds and 496 attempts
142    at spock.util.concurrent.PollingConditions.within(PollingConditions.java:185)
143    at com.company.listings.KafkaAwareBaseSpec.compareRecordSend(KafkaAwareBaseSpec.groovy:31)
144    at com.company.listings.application.worker.listener.notifier.ListingNotifierITSpec.should notify listings(ListingNotifierITSpec.groovy:44)
145
146    Caused by:
147    Condition not satisfied:
148
149    expected == getRecordSendTotal(topicName)
150    |        |  |                  |
151    10       |  0                  v4
152                false
153

We've debugged the GH Actions machine (SSH into it) and run things manually. The error still happens, but if the integration tests are run a second time (as well as subsequent runs), everything works perfectly.

We've also tried to initialize all the necessary topics and send some messages to them preemptively, but the behavior was the same.

The questions we have are:

  • Is there any issue when running Kafka dockerized in an Ubuntu machine (the error also occurred in a co-worker Ubuntu machine)?
  • Any ideas on why this is happening?

Edit

  • application.yml (Kafka related configuration)
1version: '2.1'
2
3services:
4  postgres:
5    container_name: listings-postgres
6    image: postgres:10-alpine
7    mem_limit: 500m
8    networks:
9      - listings-stack
10    ports:
11      - "5432:5432"
12    environment:
13      POSTGRES_DB: listings
14      POSTGRES_PASSWORD: listings
15      POSTGRES_USER: listings
16      PGUSER: listings
17    healthcheck:
18      test: ["CMD", "pg_isready"]
19      interval: 1s
20      timeout: 3s
21      retries: 30
22
23  listings-zookeeper:
24    container_name: listings-zookeeper
25    image: confluentinc/cp-zookeeper:6.2.0
26    environment:
27      ZOOKEEPER_CLIENT_PORT: 2181
28      ZOOKEEPER_TICK_TIME: 2000
29    networks:
30      - listings-stack
31    ports:
32      - "2181:2181"
33    healthcheck:
34      test: nc -z localhost 2181 || exit -1
35      interval: 10s
36      timeout: 5s
37      retries: 10
38
39  listings-kafka:
40    container_name: listings-kafka
41    image: confluentinc/cp-kafka:6.2.0
42    depends_on:
43      listings-zookeeper:
44        condition: service_healthy
45    environment:
46      KAFKA_BROKER_ID: 1
47      KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://listings-kafka:9092,PLAINTEXT_HOST://localhost:29092
48      KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT
49      KAFKA_INTER_BROKER_LISTENER_NAME: PLAINTEXT
50      KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
51      KAFKA_ZOOKEEPER_CONNECT: listings-zookeeper:2181
52    volumes:
53      - /var/run/docker.sock:/var/run/docker.sock
54    networks:
55      - listings-stack
56    ports:
57      - "29092:29092"
58    healthcheck:
59      test: kafka-topics --bootstrap-server 127.0.0.1:9092 --list
60      interval: 10s
61      timeout: 10s
62      retries: 50
63
64networks: {listings-stack: {}}
65name: Build
66
67on: [ pull_request ]
68
69env:
70  AWS_ACCESS_KEY_ID: ${{ secrets.TUNNEL_AWS_ACCESS_KEY_ID }}
71  AWS_SECRET_ACCESS_KEY: ${{ secrets.TUNNEL_AWS_SECRET_ACCESS_KEY }}
72  AWS_DEFAULT_REGION: 'us-east-1'
73  CIRCLECI_KEY_TUNNEL: ${{ secrets.ID_RSA_CIRCLECI_TUNNEL }}
74
75jobs:
76  build:
77    name: Listings-API Build
78    runs-on: [ self-hosted, zap ]
79
80    steps:
81      - uses: actions/checkout@v2
82        with:
83          token: ${{ secrets.GH_OLXBR_PAT }}
84          submodules: recursive
85          path: ./repo
86          fetch-depth: 0
87
88      - name: Set up JDK 11
89        uses: actions/setup-java@v2
90        with:
91          distribution: 'adopt'
92          java-version: '11'
93          architecture: x64
94          cache: 'gradle'
95
96      - name: Docker up
97        working-directory: ./repo
98        run: docker-compose up -d
99
100      - name: Build with Gradle
101        working-directory: ./repo
102        run: ./gradlew build -Dhttps.protocols=TLSv1,TLSv1.1,TLSv1.2 -x integrationTest
103
104      - name: Integration tests with Gradle
105        working-directory: ./repo
106        run: ./gradlew integrationTest -Dhttps.protocols=TLSv1,TLSv1.1,TLSv1.2
107
108      - name: Sonarqube
109        working-directory: ./repo
110        env:
111          GITHUB_TOKEN: ${{ secrets.GH_OLXBR_PAT }}
112          SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
113        run: ./gradlew sonarqube --info -Dhttps.protocols=TLSv1,TLSv1.1,TLSv1.2
114
115      - name: Docker down
116        if: always()
117        working-directory: ./repo
118        run: docker-compose down --remove-orphans
119
120      - name: Cleanup Gradle Cache
121        # Remove some files from the Gradle cache, so they aren't cached by GitHub Actions.
122        # Restoring these files from a GitHub Actions cache might cause problems for future builds.
123        run: |
124          rm -f ${{ env.HOME }}/.gradle/caches/modules-2/modules-2.lock
125          rm -f ${{ env.HOME }}/.gradle/caches/modules-2/gc.properties
126
127  boolean compareRecordSend(String topicName, int expected) {
128    def condition = new PollingConditions()
129    condition.within(kafkaProperties.listener.pollTimeout.getSeconds() * 5) {
130      assert expected == getRecordSendTotal(topicName)
131    }
132    return true
133  }
134
135  int getRecordSendTotal(String topicName) {
136    kafkaTemplate.flush()
137    return kafkaTemplate.metrics().find {
138      it.key.name() == "record-send-total" && it.key.tags().get("topic") == topicName
139    }?.value?.metricValue() ?: 0
140  }
141Condition not satisfied after 50.00 seconds and 496 attempts
142    at spock.util.concurrent.PollingConditions.within(PollingConditions.java:185)
143    at com.company.listings.KafkaAwareBaseSpec.compareRecordSend(KafkaAwareBaseSpec.groovy:31)
144    at com.company.listings.application.worker.listener.notifier.ListingNotifierITSpec.should notify listings(ListingNotifierITSpec.groovy:44)
145
146    Caused by:
147    Condition not satisfied:
148
149    expected == getRecordSendTotal(topicName)
150    |        |  |                  |
151    10       |  0                  v4
152                false
153spring:
154  kafka:
155    bootstrap-servers: localhost:29092
156    producer:
157      batch-size: 262144
158      buffer-memory: 536870912
159      retries: 1
160      key-serializer: org.apache.kafka.common.serialization.StringSerializer
161      value-serializer: org.apache.kafka.common.serialization.ByteArraySerializer
162      acks: all
163      properties:
164        linger.ms: 0
165

ANSWER

Answered 2021-Nov-03 at 19:11

We identified some test sequence dependency between the Kafka tests.

We updated our Gradle version to 7.3-rc-3 which has a more deterministic approach to test scanning. This update "solved" our problem while we prepare to fix the tests' dependencies.

Source https://stackoverflow.com/questions/69284830

Community Discussions contain sources that include Stack Exchange Network

Tutorials and Learning Resources in Groovy

Tutorials and Learning Resources are not available at this moment for Groovy

Share this Page

share link

Get latest updates on Groovy