Black Duck fails to run gradlew dependencies successfully - java

Since upgrading from Gradle 6.7.1 to 7.0 (which may be a red herring), Black Duck scans of my Gradle project now fail.
Here is the error message:
* Where:
Initialization script '/root/blackduck/runs/2022-01-18-19-06-00-216/shared/gradle/init-detect.gradle' line: 40
* What went wrong:
Execution failed for task ':dependencies'.
> No signature of method: org.gradle.api.tasks.diagnostics.internal.dependencies.AsciiDependencyReportRenderer.startProject() is applicable for argument types: (org.gradle.api.internal.project.DefaultProject_Decorated) values: [root project '<redacted&gt']
Possible solutions: startProject(org.gradle.api.tasks.diagnostics.internal.ProjectDetails), startProject(org.gradle.api.tasks.diagnostics.internal.ProjectDetails)
Builds are successful when the Gradle build is run without Black Duck.
The Black Duck scan is run with the following command:
bash detect.sh --blackduck.url=<redacted> --blackduck.trust.cert=true --blackduck.api.token=<redacted> --detect.project.name=<redacted> --detect.project.version.name=Developer --detect.source.path=.
Here is my full build.gradle:
buildscript {
repositories {
maven {
url "https://<redacted>/nexus/repository/maven-central"
}
maven {
url "https://<redacted>/nexus/repository/thirdparty"
}
maven {
url "https://<redacted>/nexus/repository/gradle-plugins"
}
}
}
plugins {
id "java"
}
def nexusUsername = (System.getenv("NEXUS_USERNAME") != null ? System.getenv("NEXUS_USERNAME") : (project.hasProperty('NEXUS_USERNAME') ? "$NEXUS_USERNAME" : ""))
def nexusPassword = (System.getenv("NEXUS_PASSWORD") != null ? System.getenv("NEXUS_PASSWORD") : (project.hasProperty('NEXUS_PASSWORD') ? "$NEXUS_PASSWORD" : ""))
repositories {}
ext {}
dependencies {}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
sourceCompatibility = 11
targetCompatibility = 11
sourceSets {
main {
java {
srcDirs = ['src/main/java']
}
}
}
My ideas for what could be wrong:
There is a bug in the auto-generated /root/blackduck/runs/2022-01-18-19-06-00-216/shared/gradle/init-detect.gradle file (maybe Black Duck doesn't play nice with Gradle 7.0)
I run the detect.sh script with the wrong arguments
There is something wrong with my build.gradle file
I am looking for any suggestions on how to solve this problem so that my Black Duck scans can run successfully once more.

The problem was I was using an older version of the Black Duck detect.sh script. I was using version 6.9.1. Once I upgraded to using version 7.6.0, the Black Duck scan worked once more.
To use the new version of the script, you can do the following (note the detect7.sh in the URL; if you download plain detect.sh you will get an old version):
curl --fail https://detect.synopsys.com/detect7.sh -o detect.sh
export DETECT_LATEST_RELEASE_VERSION=7.6.0
bash detect.sh <args>

Related

GraalVM "Invalid GAV coordinates" error? (Spring boot 3)

Recently I downloaded Spring Boot 3 to test the embedded GraalVM. I run the `./gradlew native compile command the result is:
$ ./gradlew nativeCompile
FAILURE: Build failed with an exception.
* What went wrong:
Could not determine the dependencies of task ':nativeCompile'.
> Invalid GAV coordinates: groovy:it_groovy_comparre: (expected format: groupId:artifactId: version)
....
BUILD FAILED in 752ms
What is my problem with dependencies? When I run that command in debug mode there is nothing new except this error.
NOTE:
my $JAVA_HOME variable value is: /home/<my username>/.jdks/graalvm-ce-java17-22.3.0/, which point to a Graalvm java
my build automation tool is Gradle.
When I tested the command in groovy the result was the same
I found the solution.
Firstly I added a version to my build.gradle file like this :
plugins {
// ...
}
group = 'groovy'
version = '1' // <-------------- HERE
sourceCompatibility = '17'
configurations {
//...
}
Just before executing the command ./gradlew nativeCompile, I ran the following two commands :
$ ./gradlew processAot
...
$ ./gradlew processTestAot
...
After that, everything works fine.

Could not find method outputDir() on cucumber Java source of type org.gradle.api.internal.file.DefaultSourceDirectorySet

I am not able to run the cucumber task for the "com.github.samueltbrown.cucumber" plugin.
I get the following error:
FAILURE: Build failed with an exception.
* Where:
Build file '/Users/freid/app/build.gradle' line: 118
* What went wrong:
A problem occurred evaluating root project 'app'.
> Could not find method outputDir() for arguments [/Users/freid/app/src/cucumber/java] on cucumber Java source of type org.gradle.api.internal.file.DefaultSourceDirectorySet.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 0s
Here is my build.gradle file:
buildscript {
ext {
springBootVersion='2.2.4.RELEASE'
lombokVersion='1.18.4'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
plugins {
id 'org.springframework.boot' version '2.2.4.RELEASE'
id 'java'
id 'com.github.psxpaul.execfork' version '0.1.8'
id "com.jfrog.artifactory" version "4.7.2"
id "com.github.samueltbrown.cucumber" version "0.9"
}
dependencies {
testCompile 'info.cukes:cucumber-java:1.2.4'
}
sourceSets {
cucumber {
java {
compileClasspath += main.output + test.output
runtimeClasspath += main.output + test.output
srcDir file('src/cucumber/java')
}
resources.srcDir file('src/cucumber/resources')
}
}
cucumber {
formats = ['html:build/reports/html', 'json:build/reports/cucumber.json']
jvmOptions {
environment 'tag', System.getProperty("tag")
environment 'cucumber.local.server', 'localhost'
}
}
Given that the plugin com.github.samueltbrown.cucumber version 0.9 was released in 2015 and you are trying to run with a recent Spring Boot version, I would assume you are using a recent Gradle version as well.
So I believe you are hitting an incompatibility between the plugin and the Gradle version. Most likely an API changed and what the plugin does internally no longer works.
[/Users/freid/app/src/cucumber/java] looks like the toString of a collection of files, while SourceDirectorySet.outputDir only accepts a single File. So my guess is that the API of what returns the value that is used changed from a single file to a file collection at some point.

gradle java9 Could not target platform: 'Java SE 9' using tool chain: 'JDK 8 (1.8)'

I want to use java9 on my gradle project inside eclipse oxygen. When I
run:
Run as> Gradle Test on GreeterTest.java
with the following code:
package hello.test;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
import hello.Greeter;
class GreeterTest {
#Test
void test() {
Greeter greeter = new Greeter();
assertEquals("Hello world", greeter.sayHello());
}
}
and with the class I test as:
package hello;
public class Greeter {
public String sayHello() {
return "Hello world!";
}
}
I get the error message
Could not target platform: 'Java SE 9' using
tool chain: 'JDK 8 (1.8)'.
My eclipse.init is
-startup ../Eclipse/plugins/org.eclipse.equinox.launcher_1.4.0.v20161219-1356.jar
--launcher.library /Users/stein/.p2/pool/plugins/org.eclipse.equinox.launcher.cocoa.macosx.x86_64_\1.1.550.v20170928-1359
-product org.eclipse.epp.package.jee.product
-showsplash org.eclipse.epp.package.common
--launcher.defaultAction openFile
--launcher.a/Library/Java/JavaVirtualMachines/jdk-9.0.1.jdk/Contents/Home/jre/bin
-vmargs
-Dosgi.requiredJavaVersion=1.9
-Dosgi.instance.area.default=#user.home/eclipse-workspace
-XX:+UseG1GC
-XX:+UseStringDeduplication
--add-modules=ALL-SYSTEM
-XstartOnFirstThread
-Dorg.eclipse.swt.internal.carbon.smallFonts
-Dosgi.requiredJavaVersion=1.9
-Xms256m
-Xmx1024m
--add-modules=ALL-SYSTEM
-Xdock:icon=../Resources/Eclipse.icns
-XstartOnFirstThread
-Dorg.eclipse.swt.internal.carbon.smallFonts
-Declipse.p2.max.threads=10
-Doomph.update.url=http://download.eclipse.org/oomph/updates/milestone/latest
-Doomph.redirection.index.redirection=index:/->http://git.eclipse.org/c/oomph/org.eclipse.oomph.git/plain/setups/
I have added JAVA_HOME
I have added the build path
I have change the compile parameter
I have set the compile parameter in the Build.Gradle.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'org.junit.platform:junit-platform-gradle-plugin:1.0.2'
}
}
repositories {
mavenCentral()
}
ext.junit4Version = '4.12'
ext.junitVintageVersion = '4.12.2'
ext.junitPlatformVersion = '1.0.2'
ext.junitJupiterVersion = '5.0.2'
ext.log4jVersion = '2.9.0'
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.junit.platform.gradle.plugin'
jar {
baseName = 'junit5-gradle-consumer'
version = '1.0.0-SNAPSHOT'
}
compileJava {
sourceCompatibility = 9
targetCompatibility = 9
}
compileTestJava {
sourceCompatibility = 9
targetCompatibility = 9
options.compilerArgs += '-parameters'
}
junitPlatform {
// platformVersion '1.0.2'
filters {
engines {
// include 'junit-jupiter', 'junit-vintage'
// exclude 'custom-engine'
}
tags {
// include 'fast'
exclude 'slow'
}
// includeClassNamePattern '.*Test'
}
// configurationParameter 'junit.jupiter.conditions.deactivate', '*'
// enableStandardTestTask true
// reportsDir file('build/test-results/junit-platform') // this is the default
logManager 'org.apache.logging.log4j.jul.LogManager'
}
dependencies {
// JUnit Jupiter API and TestEngine implementation
testCompile("org.junit.jupiter:junit-jupiter-api:${junitJupiterVersion}")
testRuntime("org.junit.jupiter:junit-jupiter-engine:${junitJupiterVersion}")
// If you also want to support JUnit 3 and JUnit 4 tests
testCompile("junit:junit:${junit4Version}")
testRuntime("org.junit.vintage:junit-vintage-engine:${junitVintageVersion}")
// To avoid compiler warnings about #API annotations in JUnit code
//testCompileOnly('org.apiguardian:apiguardian-api:1.0.0')
// To use Log4J's LogManager
testRuntime("org.apache.logging.log4j:log4j-core:${log4jVersion}")
testRuntime("org.apache.logging.log4j:log4j-jul:${log4jVersion}")
// Only needed to run tests in an (IntelliJ) IDE(A) that bundles an older version
testRuntime("org.junit.platform:junit-platform- launcher:${junitPlatformVersion}")
}
task wrapper(type: Wrapper) {
description = 'Generates gradlew[.bat] scripts'
gradleVersion = '4.1'
}
What must I do to get this to run?
You should probably try to update your JAVA_HOME in system variables and
Java version used in eclipse to be consistent to
JAVA_HOME=/path/to/jdk9
In MacOSX, something like :
JAVA_HOME = /Library/Java/JavaVirtualMachines/jdk-9.0.1.jdk/Contents/Home/bin
As informed in comments, the default path on Linux would be :
/usr/lib/jvm/java-9-openjdk
From what I can see, it is the Gradle version issue. (Gradle and Java 9 compatibility issue).
You need to upgrade the wrapper to 4.3.1, cli ref:
# upgrade Gradle to 4.3.1
gradle wrapper --gradle-version 4.3.1 # not ./gradlew
Let me know if that works.
I changed the java_home and upgraded Gradle. Now it is working.
I faced the issue because in IntelliJ Idea in the Settings > Build Tools > Gradle
In "Gradle" section, Gradlje JVM used an incorrect Java version. So I specify to use JAVA_HOME and it fixes the issue.
Additionally to the other ways you tried:
Gradle has a default JVM set in your %userprofile%/.gradle/gradle.properties.
This is in the folder "C:\Users\j.gradle\gradle.properties" for me:
org.gradle.java.home=C:/Program Files/AdoptOpenJDK/jdk-11.0.7.10-hotspot
That's where you should also put your newer JVM to make sure gradle can compile newer projects.
What I did to fix this problem was I did this on my imported project build.gradle on compileJava section I changed sourceCompatibility and targetCompatibility into 8. It works for me. this happen when you import project from other resource, which is build in different version.
in Eclipse make sure you have proper settings on Gradle build configuration.
I faced the same error with different JDK version, so i used the following code which works fine.
compileJava {
options.fork = true
options.forkOptions.javaHome = file('/Library/Java/JavaVirtualMachines/jdk-11.0.5.jdk/Contents/Home')
targetCompatibility = 11
sourceCompatibility = 11
}
I had a similar issue with eclipse, I had to set JAVA_HOME in Properties -> Gradle.
For me the problem was that I used
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_10
targetCompatibility JavaVersion.VERSION_1_10
}
but the project was configured for Java 1.8. So I changed these to 1_8 and it works.

Gradle build failed on Travis CI

I used filteringCharset = 'UTF-8' because of encoding problems in ProcessResources in build.gradle. This build succeeded on my desktop, but failed on Travis CI. I guess this is the problem with Travis CI's Gradle. So I tried to update the version but could not find any information. Is this the problem with the Gradle version? If yes, what can I do?
Travis build error:
FAILURE: Build failed with an exception.
* Where:
Build file '/home/travis/build/EntryPointKR/K-Security/build.gradle' line: 43
* What went wrong:
A problem occurred evaluating root project 'K-Security'.
> No such property: filteringCharset for class: org.gradle.language.jvm.tasks.ProcessResources_Decorated
Full travis build log: https://travis-ci.org/EntryPointKR/K-Security/builds/201771722
.travis.yml:
language: java
sudo: false
jdk:
- oraclejdk8
addons:
apt:
packages:
- oracle-java8-installer
Problem code in build.gradle
processResources {
filteringCharset = 'UTF-8' // Here
filter ReplaceTokens, tokens: [
"version" : project.version,
"pluginName": rootProject.name,
"mainClass" : "cloud.swiftnode.ksecurity.KSecurity",
"author" : "EntryPoint"
]
}
This is very likely due to a mismatch between your gradle version and the gradle version installed in the java image. It was introduced in Gradle 2.14. The easiest fix is to use gradle wrapper to enforce the same version in both environments.
Simply add the wrapper task:
task wrapper(type: Wrapper) {
gradleVersion = '3.3'
}
It should be possible to run gradle wrapper in before_install, or simply bundle the gradle-wrapper jar with your project. Travis CI will detect gradle wrapper and use gradlew instead of gradle.
If you are using Windows on your local machine, make sure you commit the gradlew script with executable flag.

How do I add default JVM arguments with Gradle

I need to add default JVM options to my jar, when build with Gradle.
From the documentation I got that I have to set:
applicationDefaultJvmArgs = ["-Djavafx.embed.singleThread=true"]
I have not much experience with Gradle and the developer that wrote the build.gradle file wrote it different from what most websites give as examples.
Here is the build.gradle:
apply plugin: 'java'
apply plugin: 'eclipse'
version = '0.1'
repositories {
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.+'
compile 'placeholder'
}
task release(type: Jar) {
manifest {
attributes("Implementation-Title": "placeholder",
"Implementation-Version": version,
'Main-Class': 'placeholder.Application')
}
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
with jar
}
task wrapper(type: Wrapper) {
gradleVersion = '2.2.1'
}
I don't know where to put the arguments. I tried putting them in different locations, but I always get:
A problem occurred evaluating root project 'placeholder'.
> No such property: applicationDefaultJvmArgs for class: org.gradle.api.tasks.bundling.Jar_Decorated
Much Thanks,
Jhonny
From the top of my head I can think of 2 options:
Option1: Do what #Ethan said, it'll likely work:
package placeholder;
//your imports
public class Application{
static {
System.getProperties().set("javafx.embed.singleThread", "true");
}
// your code
public static void main(String... args){
//your code
}
}
Option 2: Use the application plugin + default jvm values
build.gradle:
apply plugin: 'application'
//your code
applicationDefaultJvmArgs = ["-Djavafx.embed.singleThread=true"]
Now you can run your code 2 ways:
From gradle
$gradle run
From distribution(script). from the generated script that the application plugin will provide:
$gradle clean build distZip
Then gradle will generate a zip file somewhere under ${your.projectdir}/build. Find the zip then unzip it and under /bin you'll find a ${yourproject}.bat and ${yourproject} executables. One is for Linux/mac/unix (${yourproject}) the other one is for windows (${yourproject.bat})
Option 3 (Android Developer): Use gradle.properties to set jvm argument
# Project-wide Gradle settings.
# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx1024m -XX:MaxPermSize=256m
# org.gradle.jvmargs=-Xmx1024m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
# You can setup or customize it according to your needs and combined with the above default value.
org.gradle.jvmargs=-Djavafx.embed.singleThread=true
For more info on how to use gradle build environment on docs.gradle.org
applicationDefaultJvmArgs is provided by the Application plugin. So if you apply that plugin, the error would probably go away, and you should be able to execute the program by issuing gradle run once you set the mainClassName property to the fully qualified class name, the main method of which you want to invoke.
Using a local gradlew is the easiest.
Just append to DEFAULT_JVM_OPTS.
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m" "-XX:+AllowRedefinitionToAddDeleteMethods"'
you can use command-line with gradle taskļ¼š
class AppRun extends JavaExec {
private boolean withDebug
#Option(option = "with-debug", description = "enable debug for the process. ")
public void setDebugMode(boolean debug) {
this.withDebug = debug
}
public boolean getDebugMode() {
return this.withDebug
}
}
task run(type: AppRun) {
}
then run task with options
gradle run --with-debug
set this to Your java main Class.
static {
System.setProperty("nashorn.args", "--no-deprecation-warning");
}

Categories