I am trying to run detektBaseline gradle task but facing following Exception
Process ‘command ‘/Applications/Android
Studio.app/Contents/jre/jdk/Contents/Home/bin/java’’ finished with
non-zero exit value 255
my project level gradle configuration for detekt
plugins {
id “io.gitlab.arturbosch.detekt” version “1.0.0.RC6-4”
}
detekt {
version = “1.0.0.RC6-4”
defaultProfile {
input = “$projectDir/rlm/src/main/java”
config = “$projectDir/default-detekt-config.yml”
filters = “./resources/.,./build/.”
}
Any kind of help or guideline would be appreciated.
Related
spotlessDiagnose diverges after 10 steps message, is seen and doesn't let us modify importOrder across all files. How do we resolve this
gradlew spotlessDiagnose
> Task :spotlessJavaDiagnose
src/main/java/com/foo/repository/Foo.java diverges after 10 steps
src/main/java/com/foo/repository/Bar.java diverges after 10 steps
My definition looks like this
spotless {
java {
importOrder()
}
}
I’m updating the gradle version of my application, it was with version 2.3 and I’m going to 6.7.1
I changed some things, of course, but this error I’m not able to resolve:
> Could not set unknown property 'testClassesDir' for task ':systemtestRun' of type org.gradle.api.tasks.testing.Test.
build.gradle:
task systemtestRun(type: Test) {
description 'run tests'
testClassesDir = sourceSets.systemtest.output.classesDirs
classpath = sourceSets.systemtest.runtimeClasspath + sourceSets.test.runtimeClasspath }
It should be testClassesDirs not testClassesDir:
tasks.register('systemtestRun', Test) {
description = 'Runs system tests.'
group = 'verification'
testClassesDirs = sourceSets.systemtest.output.classesDirs
classpath = sourceSets.systemtest.runtimeClasspath
}
I've got a Gradle project which uses a Java version specified with the toolchain API:
val minimumJava = JavaLanguageVersion.of(8)
val maximumJava = JavaLanguageVersion.of(16)
java {
toolchain {
languageVersion.set(minimumJava)
vendor.set(JvmVendorSpec.ADOPTOPENJDK)
}
}
I would like to be able to compile with the minimum supported Java version, then run the tests with all the JDKs the project supports.
I tried the following, but apparently only the original tests get executed, all other tests don't, even though the required JDKs get correctly downloaded and set up:
for (javaVersion in JavaLanguageVersion.of(minimumJava.asInt() + 1)..maximumJava) {
val base = tasks.test.get()
val testTask = tasks.register<Test>("testUnderJava${javaVersion.asInt()}") {
javaLauncher.set(
javaToolchains.launcherFor {
languageVersion.set(javaVersion)
}
)
classpath = base.classpath
testClassesDirs = base.testClassesDirs
isScanForTestClasses = true
}
tasks.test.configure { finalizedBy(testTask) }
}
Here is a run in a dumb terminal:
❯ TERM=dumb ./gradlew test testUnderJava10 --rerun-tasks --scan
Picked up _JAVA_OPTIONS: -Dawt.useSystemAAFontSettings=on
<<<SNIP>>>
> Task :testClasses
> Task :test
Picked up _JAVA_OPTIONS: -Dawt.useSystemAAFontSettings=on
Gradle Test Executor 4 STANDARD_OUT
~~~ Kotest Configuration ~~~
-> Parallelization factor: 1
-> Concurrent specs: null
-> Global concurrent tests: 1
-> Dispatcher affinity: true
-> Default test timeout: 600000ms
-> Default test order: Sequential
-> Default isolation mode: SingleInstance
-> Global soft assertions: false
-> Write spec failure file: false
-> Fail on ignored tests: false
-> Spec execution order: SpecExecutionOrder
-> Remove test name whitespace: false
-> Append tags to test names: false
-> Extensions
- io.kotest.engine.extensions.SystemPropertyTagExtension
- io.kotest.core.extensions.RuntimeTagExtension
- io.kotest.engine.extensions.RuntimeTagExpressionExtension
org.danilopianini.template.test.Tests > A greeting should get printed STARTED
org.danilopianini.template.test.Tests > A greeting should get printed STANDARD_OUT
[:hello=SUCCESS]
> Task :hello
Hello from Danilo Pianini
BUILD SUCCESSFUL in 2s
1 actionable task: 1 executed
org.danilopianini.template.test.Tests > A greeting should get printed PASSED
<<<Other tests have no output!>>>
> Task :testUnderJava9
> Task :testUnderJava8
> Task :testUnderJava16
> Task :testUnderJava15
> Task :testUnderJava14
> Task :testUnderJava13
> Task :testUnderJava12
> Task :testUnderJava11
> Task :testUnderJava10
BUILD SUCCESSFUL in 23s
36 actionable tasks: 36 executed
<<<SNIP>>>
From the build scan, it appears that tests are not executed but those with JDK8. I'm puzzled, the docs say that this should be straightforward:
tasks.register<Test>("testsOn14") {
javaLauncher.set(javaToolchains.launcherFor {
languageVersion.set(JavaLanguageVersion.of(14))
})
}
I think I worked out the root cause of the issues I was experiencing, I'm posting the solution in case someone else runs into similar issues.
I had the following tests configuration:
tasks.test {
useJUnitPlatform()
testLogging {
showStandardStreams = true
showCauses = true
showStackTraces = true
events(*org.gradle.api.tasks.testing.logging.TestLogEvent.values())
exceptionFormat = org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL
}
}
Which was instructing the task called test to useJunitPlatform(). This setting does not get automatically propagated to all subsequent Test tasks (of course). So, in this case, the solution is simply to use instead:
tasks.withType<Test> {
// Same configuration as above
}
Update 2022-03-16
I decided to create a multi-JVM testing plugin for Gradle, so that all the test tasks get created and much less boilerplate is required across projects.
Update 2023-01-17
Gradle recommends using the task configuration avoidance API.
tasks.withType<Test>().configureEach {
// Same configuration as above
}
When I am trying to edit a property within Gradle it re-formats my entire properties file and removes the comments. I am assuming this is because of the way Gradle is reading and writing to the properties file. I would like to just change a property and leave the rest of the properties file untouched including leaving the current comments in place and order of the values. Is this possible to do using Gradle 5.2.1?
I have tried to just use setProperty (which does not write to the file), used a different writer: (versionPropsFile.withWriter { versionProps.store(it, null) } )
and tried a different way to read in the properties file: versionProps.load(versionPropsFile.newDataInputStream())
Here is my current Gradle code:
File versionPropsFile = file("default.properties");
def versionProps = new Properties()
versionProps.load(versionPropsFile.newDataInputStream())
int version_minor = versionProps.getProperty("VERSION_MINOR")
int version_build = versionProps.getProperty("VERSION_BUILD")
versionProps.setProperty("VERSION_MINOR", 1)
versionProps.setProperty("VERSION_BUILD", 2)
versionPropsFile.withWriter { versionProps.store(it, null) }
Here is a piece of what the properties file looks like before gradle touches it:
# Show splash screen at startup (yes* | no)
SHOW_SPLASH = yes
# Start in minimized mode (yes | no*)
START_MINIMIZED = no
# First day of week (mon | sun*)
# FIRST_DAY_OF_WEEK = sun
# Version number
# Format: MAJOR.MINOR.BUILD
VERSION_MAJOR = 1
VERSION_MINOR = 0
VERSION_BUILD = 0
# Build value is the date
BUILD = 4-3-2019
Here is what Gradle does to it:
#Wed Apr 03 11:49:09 CDT 2019
DISABLE_L10N=no
LOOK_AND_FEEL=default
ON_MINIMIZE=normal
CHECK_IF_ALREADY_STARTED=YES
VERSION_BUILD=0
ASK_ON_EXIT=yes
SHOW_SPLASH=yes
VERSION_MAJOR=1
VERSION_MINOR=0
VERSION_BUILD=0
BUILD=04-03-2019
START_MINIMIZED=no
ON_CLOSE=minimize
PORT_NUMBER=19432
DISABLE_SYSTRAY=no
This is not a Gradle issue per se. The default Properties object of Java does not preserve any layout/comment information of properties files. You can use Apache Commons Configuration, for example, to get layout-preserving properties files.
Here’s a self-contained sample build.gradle file that loads, changes and saves a properties file, preserving comments and layout information (at least to the degree that is required by your example file):
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'org.apache.commons:commons-configuration2:2.4'
}
}
import org.apache.commons.configuration2.io.FileHandler
import org.apache.commons.configuration2.PropertiesConfiguration
import org.apache.commons.configuration2.PropertiesConfigurationLayout
task propUpdater {
doLast {
def versionPropsFile = file('default.properties')
def config = new PropertiesConfiguration()
def fileHandler = new FileHandler(config)
fileHandler.file = versionPropsFile
fileHandler.load()
// TODO change the properties in whatever way you like; as an example,
// we’re simply incrementing the major version here:
config.setProperty('VERSION_MAJOR',
(config.getProperty('VERSION_MAJOR') as Integer) + 1)
fileHandler.save()
}
}
I'm trying add a Java installation on my Yocto build. I would like to run on my embedded system a Java application I developed but I can't correctly install Java.
When I try to run java I get the following:
./java: No such file or directory
I googled for a solution and found that I need to install libc6 32 bit version.
I proceeded to modify my local.conf file as following:
MACHINE ??= "intel-corei7-64"
require conf/multilib.conf
MULTILIBS = "multilib:lib32"
DEFAULTTUNE_virtclass-multilib-lib32 = "x86"
DISTRO ?= "poky"
PACKAGE_CLASSES ?= "package_rpm"
SDKMACHINE ?= "x86_64"
EXTRA_IMAGE_FEATURES ?= "debug-tweaks"
USER_CLASSES ?= "buildstats image-mklibs image-prelink"
PATCHRESOLVE = "noop"
BB_DISKMON_DIRS = "\
STOPTASKS,${TMPDIR},1G,100K \
STOPTASKS,${DL_DIR},1G,100K \
STOPTASKS,${SSTATE_DIR},1G,100K \
STOPTASKS,/tmp,100M,100K \
ABORT,${TMPDIR},100M,1K \
ABORT,${DL_DIR},100M,1K \
ABORT,${SSTATE_DIR},100M,1K \
ABORT,/tmp,10M,1K"
PACKAGECONFIG_append_pn-qemu-native = " sdl"
PACKAGECONFIG_append_pn-nativesdk-qemu = " sdl"
CONF_VERSION = "1"
CORE_IMAGE_EXTRA_INSTALL = " lib32-glibc"
CORE_IMAGE_EXTRA_INSTALL += "opencv opencv-samples libopencv-core-dev libopencv-highgui-dev libopencv-imgproc-dev libopencv-objdetect-dev libopencv-ml-dev"
But i get this error:
Build Configuration:
BB_VERSION = "1.32.0"
BUILD_SYS = "x86_64-linux"
NATIVELSBSTRING = "universal-4.8"
TARGET_SYS = "x86_64-poky-linux"
MACHINE = "intel-corei7-64"
DISTRO = "poky"
DISTRO_VERSION = "2.2.1"
TUNE_FEATURES = "m64 corei7"
TARGET_FPU = ""
meta
meta-poky
meta-yocto-bsp = "morty:924e576b8930fd2268d85f0b151e5f68a3c2afce"
meta-intel = "morty:6add41510412ca196efb3e4f949d403a8b6f35d7"
meta-oe = "morty:fe5c83312de11e80b85680ef237f8acb04b4b26e"
meta-intel-realsense = "morty:2c0dfe9690d2871214fba9c1c32980a5eb89a421"
Initialising tasks: 100% |#####################################################################################################################################################################################################| Time: 0:00:22
NOTE: Executing SetScene Tasks
NOTE: Executing RunQueue Tasks
ERROR: rmc-1.0-r0 do_package: QA Issue: rmc: Files/directories were installed but not shipped in any package:
/usr/lib
/usr/lib/librmclefi.a
/usr/lib/librsmpefi.a
Please set FILES such that these items are packaged. Alternatively if they are unneeded, avoid installing them or delete them within do_install.
rmc: 3 installed and not shipped files. [installed-vs-shipped]
ERROR: rmc-1.0-r0 do_package: Fatal QA errors found, failing task.
ERROR: rmc-1.0-r0 do_package: Function failed: do_package
ERROR: Logfile of failure stored in: /home/dalben/WorkingBuild/poky/filec/tmp/work/corei7-64-poky-linux/rmc/1.0-r0/temp/log.do_package.16424
ERROR: Task (/home/dalben/WorkingBuild/poky/meta-intel/common/recipes-bsp/rmc/rmc.bb:do_package) failed with exit code '1'
NOTE: Tasks Summary: Attempted 2954 tasks of which 2937 didn't need to be rerun and 1 failed.
Summary: 1 task failed:
/home/dalben/WorkingBuild/poky/meta-intel/common/recipes-bsp/rmc/rmc.bb:do_package
Summary: There were 3 ERROR messages shown, returning a non-zero exit code.
Any help is appreciated.
EDIT: Updated question here.
For your information, you will need to do a lot of work in putting Java into your image.
Your current image does not have any java related programs installed since I do not see meta-java in your compile process.
CORE_IMAGE_EXTRA_INSTALL is restricted to OE Core images; So if you have your own image recipe, the variable will does not work unless you inherit core-image.bbclass
Here is an example on putting "openjdk-7-jre" to the image: http://wiki.hioproject.org/index.php?title=OpenHAB:_WeMo_Switch
The key elements are: meta-java, meta-oracle-java .
You will need to add them to your conf/bblayers.conf
BBLAYERS = " \
${BSPDIR}/sources/meta-java \
${BSPDIR}/sources/meta-oracle-java \
"
In conf/local.conf, add this line to install openjdk-7-jre.
IMAGE_INSTALL_append = " openjdk-7-jre "
To add more on what you need, check on https://layers.openembedded.org/layerindex/branch/master/layers/