Gradle does not run unit tests in groovy - build.gradle

I am trying to run a unit test in groovy. The test class itself never gets called.
My build.gradle is below:
apply plugin: 'groovy'
sourceCompatibility = 1.8
repositories {
mavenCentral()
maven { url 'https://repo.jenkins-ci.org/releases/' }
}
dependencies {
implementation 'org.codehaus.groovy:groovy-all:3.0.7'
testImplementation 'junit:junit:4.12'
testImplementation "com.lesfurets:jenkins-pipeline-unit:1.3"
}
tasks.withType(Test) {
testLogging {
exceptionFormat "full"
events "started", "skipped", "passed", "failed"
showStandardStreams true
}
}
test {
useJUnitPlatform()
testLogging {
events 'passed', 'skipped', 'failed'
}
// delete old test reports
dependsOn cleanTest
// don't stop if tests fail
ignoreFailures = true
// minimize logging
testLogging.maxGranularity = 0
// show stdout from tests
onOutput {
dest, event -> print event.message
}
// show test results
def results = []
afterTest { desc, result ->
println "${desc.className.split("\\.")[-1]}: " +
"${desc.name}: ${result.resultType}"
}
afterSuite { desc, result ->
if (desc.className) { results << result }
}
// show summary
doLast {
println "Tests: ${results.sum { it.testCount }}" +
", Failures: ${results.sum { it.failedTestCount }}" +
", Errors: ${results.sum { it.exceptions.size() }}" +
", Skipped: ${results.sum { it.skippedTestCount }}"
}
}
My folder structure is as below :
src
---main
---groovy
---<groovy class>
---test
---groovy
---testClass.groovy
When I run .gradlew test then my console shows
Task :test
Tests: null, Failures: null, Errors: null, Skipped: null
BUILD SUCCESSFUL in 5s
4 actionable tasks: 2 executed, 2 up-to-date
The tests are null eventhough I have declared a test class in groovy.
Could someone help in executing gradle test.

The file name and class name were different due to which it wasn't getting called. It started working once I gave it the correct name.

Related

how can print return object of data in Packer?

Please refer to below code
data "amazon-ami" "ubuntu" {
most_recent = true
filters = {
virtualization-type = "hvm"
name = "ubuntu/images/*ubuntu-focal-20.04-amd64-server-*"
root-device-type = "ebs"
}
owners = ["099720109477"]
}
source "null" "one" {
communicator = "none"
}
build {
name = "source-ouput"
sources = ["source.null.one"]
provisioner "shell-local" {
inline = [
"echo ${data.amazon-ami.ubuntu}", ##### <--- problem happens here
]
}
}
As you can see in the code, I want to print out the return value of data "amazon-ami" "ubuntu"
If I run this with packer build .. error occurs like below
Error: Failed preparing provisioner-block "shell-local" ""
on main.pkr.hcl line 20:
(source code not available)
main.pkr.hcl:22,15-37: Invalid template interpolation value; Cannot include the
given value in a string template: string required.
Is there any solution to print the object that returned by data?

Create JSON file from Groovy variables in Pipeline - jenkins job

i am new to jenkins, i have a pipline job with parameters.
I want to create a JSON file and write my parameters there.
(and then let my jar file read that JSON file and run according to it)
how can i do this in groovy?
this is my jenkins file:
pipeline {
agent {
label "create_pass_criteria"
}
parameters {
string(name: 'IP', description: 'Please enter your ip')
password(name: 'PASSWORD',description: 'Please enter your mx password')
string(name: 'NAME', description: 'Please enter the name ')
}
tools {
maven 'maven-3.3.9'
}
options
{
buildDiscarder(logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '', daysToKeepStr: '', numToKeepStr: '20'))
gitLabConnection('gitlab')
}
stages {
stage('Git Clone') {
steps {
updateGitlabCommitStatus name: 'Build', state: 'running'
checkout([
$class : 'GitSCM',
branches : [[name: '*/master']],
doGenerateSubmoduleConfigurations: false,
extensions : [],
submoduleCfg : [],
userRemoteConfigs : [[credentialsId: GIT_CRED, url: GIT_PATH]]
])
}
}
stage('Build') {
steps {
sh 'mvn install'
}
}
stage('run') {
steps {
sh 'java -jar /var/lib/jenkins/workspace/create_pass_criteria/target/create_pass_criteria-8.0.125-SNAPSHOT.jar'
}
}
}
post {
success {
updateGitlabCommitStatus name: 'Build', state: 'success'
emailext(
to: EMAIL_ADDR,
subject: "Success Pipeline: ${currentBuild.fullDisplayName}",
body: "Pipeline URL: ${env.BUILD_URL}",
mimeType: 'text/html'
)
}
failure {
updateGitlabCommitStatus name: 'Build', state: 'failed'
emailext(
to: EMAIL_ADDR,
subject: "Failed Pipeline: ${currentBuild.fullDisplayName}",
body: "Pipeline URL: ${env.BUILD_URL}",
mimeType: 'text/html'
)
}
}
} // pipeline
i don't know if it is correct but this is what i need to add to my Jenkins file?:
node{
//to create json declare a sequence of maps/arrays in groovy
//here is the data according to your sample
def data = [
attachments:[
[
mxIp : params.MX_IP,
mxPassword : params.MX_PASSWORD,
policyName : params.POLICY_NAME,
]
]
]
writeJSON(file: 'parameters.json', json: data)
}
if yes, at which part does it is has to be?
You could put this code in a script block like this:
stage('run') {
steps {
script {
def data = [
attachments:[
[
mxIp : params.MX_IP,
mxPassword : params.MX_PASSWORD,
policyName : params.POLICY_NAME,
]
]
]
writeJSON(file: 'parameters.json', json: data)
}
sh 'java -jar /var/lib/jenkins/workspace/create_pass_criteria/target/create_pass_criteria-8.0.125-SNAPSHOT.jar'
}
}
In complex pipelines I try to create clean code by adhering to the single level of abstraction principle. In this case I would extract the script and sh steps into a separate function, which could then be called from the pipeline section as a single step:
stage('run') {
steps {
createPassCriteria()
}
}
Define the function after the closing } of the pipeline section:
void createPassCriteria() {
def data = [
attachments:[
[
mxIp : params.MX_IP,
mxPassword : params.MX_PASSWORD,
policyName : params.POLICY_NAME,
]
]
]
writeJSON(file: 'parameters.json', json: data)
sh 'java -jar /var/lib/jenkins/workspace/create_pass_criteria/target/create_pass_criteria-8.0.125-SNAPSHOT.jar'
}

Groovy LinkedHashMap returned from a Jenkins shared library is converted to String

I have a function in a Jenkins shared library which builds and returns a map object (class java.util.LinkedHashMap):
#!/usr/bin/env groovy
def call(Map config) {
script {
echo "Building nested map"
def MAP_VAR = [:]
MAP_VAR.put("one", [:])
MAP_VAR.put("two", [:])
MAP_VAR.get("one").put("a", "b")
MAP_VAR.get("two").put("c", "d")
echo "Returning: ${MAP_VAR}"
echo "Type: ${MAP_VAR.getClass()}"
return MAP_VAR
}
}
When this function runs the log output shows:
Returning: [one:[a:b], two:[c:d]]
Type: class java.util.LinkedHashMap
But when I call the function and assign the return value to a variable, it ends up being a string (class java.lang.String):
#!/usr/bin/env groovy
library identifier: 'library#main',
changelog: false,
retriever: modernSCM([ $class: 'GitSCMSource',
remote: 'git#github.com:org/repo.git',
credentialsId: 'credentials' ])
pipeline {
agent none
stages {
stage('Get map') {
agent any
steps {
script {
env.MAP_VAR = getMapVar()
}
}
}
stage('Check map') {
agent any
steps {
script {
echo "Value: ${env.MAP_VAR}"
echo "Type: ${env.MAP_VAR.getClass()}"
}
}
}
}
}
The output shows:
Value: {one={a=b}, two={c=d}}
Type: class java.lang.String
Ultimately I'm trying to access the map's properties in multiple stages within the Jenkinsfile. If I try this:
echo "Value: ${env.MAP_VAR['one']}"
I get:
groovy.lang.MissingPropertyException: No such property: one for class: java.lang.String
I've tried:
def env.MAP_VAR = getMapVar()
But that results in:
WorkflowScript: 59: unexpected token: def # line 59, column 21.
def env.MAP_VAR = getMapVar()
^
I've also tried:
def Map env.MAP_VAR = getMapVar()
But that results in:
WorkflowScript: 60: unexpected token: Map # line 60, column 25.
def Map env.MAP_VAR = getMapVar()
^
How can I get the Map/LinkedHashMap from the function as a Map/LinkedHashMap (which would allow me to access the properties/values of the map contents) and assign it to a global variable which can be used in all stages?
def env.MAP_VAR = getMapVar()
This will not work as you are trying to define a key MAP_VAR in env map.
def Map env.MAP_VAR = getMapVar()
This also will not work as you are trying to define MAP_VAR key in env map as def and also MAP. This is similar to doing something like String Integer my_var_name = something()
env.MAP_VAR = getMapVar()
You are storing the return value as a string in env environment variable map. Jenkins output is accurate given the code.
To achieve what you are trying to do, you can store it as a variable and it will work fine. In the following example, the variable goes into Groovy's script binding and will be available in the next stage. You can also define def MAP_VAR outside the pipeline block to get the same result.
#!/usr/bin/env groovy
library identifier: 'library#main',
changelog: false,
retriever: modernSCM([ $class: 'GitSCMSource',
remote: 'git#github.com:org/repo.git',
credentialsId: 'credentials' ])
pipeline {
agent none
stages {
stage('Get map') {
agent any
steps {
script {
MAP_VAR = getMapVar()
}
}
}
stage('Check map') {
agent any
steps {
script {
echo "Value: ${MAP_VAR}"
echo "Type: ${MAP_VAR.getClass()}"
}
}
}
}
}
This will print
Value: [one:[a:b], two:[c:d]]
Type: class java.util.LinkedHashMap
In stage two,
echo "${MAP_VAR['one']}"
will output
[a:b]

Groovy/Jenkins: how to prettify json string?

How do you capture a JSON object as a prettified string using a Jenkins declarative-syntax pipeline?
pipeline {
agent any
stages {
stage( "Set up" ) {
steps {
script {
hostname = "bld-machine"
reply_email = "jenkins#${hostname}.company.com"
actor_email = "user#company.com"
status_json = initStatusJson()
}
}
}
/** Try figure out the difference between "global" and "env." variables. */
stage( "Capture variables" ) {
steps {
script {
status_json.env["var"] = "${env.var}" as String
status_json.env["var2"] = "${var}" as String
}
}
}
}
post {
always {
script {
def pretty_json = writeJSON( returnText: true, json: status_json )
}
emailext( subject: "CI/CD | ${currentBuild.currentResult}",
from: "${reply_email}",
to: "${actor_email}",
mimeType: "text/plain",
body: "${pretty_json}" )
}
}
}
def initStatusJson() {
def json_obj = readJSON text: '{}'
json_obj.job = readJSON text: '{}'
json_obj.env = [:]
json_obj.job.name = "${JOB_BASE_NAME}" as String
json_obj.job.number = "${BUILD_ID}" as String
json_obj.job.server = "${JENKINS_URL}" as String
json_obj.job.visualization = "${JENKINS_URL}/blue/organizations/jenkins/${JOB_BASE_NAME}/detail/${JOB_BASE_NAME}/${BUILD_ID}/pipeline" as String
return json_obj
}
The def pretty_json =... statement in the above Jenkinsfile triggers the following error:
WARNING: Unknown parameter(s) found for class type WARNING: Unknown parameter(s) found for class type 'org.jenkinsci.plugins.pipeline.utility.steps.json.WriteJSONStep': returnText
[Pipeline] }
[Pipeline] // script
Error when executing always post condition:
java.lang.IllegalArgumentException: You have to provided a file for writeJSON.
at org.jenkinsci.plugins.pipeline.utility.steps.json.WriteJSONStepExecution.run(WriteJSONStepExecution.java:61)
at org.jenkinsci.plugins.pipeline.utility.steps.json.WriteJSONStepExecution.run(WriteJSONStepExecution.java:43)
at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution.lambda$start$0(SynchronousNonBlockingStepExecution.java:47)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
What I have tried:
The def pretty_json = writeJSON( returnText: true, json: status_json ) statement is inspired by these resources:
Jenkinsfile pipeline construct JSON object and write to file
https://www.jenkins.io/doc/pipeline/steps/pipeline-utility-steps/#writejson-write-json-to-a-file-in-the-workspace
I also tried def pretty_json = writeJSON returnText: true, json: status_json which resulted in an identical error.
status_json.toString() returns a valid, but non-prettified JSON string.
I tried def pretty_json = JsonOutput.toJson(status_json) based on Create JSON strings from Groovy variables in Jenkins Pipeline, and it generates this error:
Error when executing always post condition:
groovy.lang.MissingPropertyException: No such property: JsonOutput for class: groovy.lang.Binding
Tried def pretty_json = groovy.json.JsonOutput.prettyPrint(status_json) based on https://gist.github.com/osima/1161966, and it generated this error:
Error when executing always post condition:
groovy.lang.MissingMethodException: No signature of method: java.lang.Class.prettyPrint() is applicable for argument types: (net.sf.json.JSONObject)
Update: Attempted #daggett's solution as follows:
post {
always {
script {
def pretty_json = status_json.toString(2)
}
emailext( subject: "CI/CD | ${currentBuild.currentResult}",
from: "${reply_email}",
to: "${actor_email}",
mimeType: "text/plain",
body: "${pretty_json}" )
}
}
...and also tried some variations like pretty_json = ... (instead of def pretty_json = ...) and also moving the pretty_json assignment outside the script{...} scope...but none worked.
Inside the script{...} context, the .toString(2) generated this error:
Scripts not permitted to use method net.sf.json.JSON toString int.
Outside the script{...} context, it generated what I interpret to be a "syntax error":
WorkflowScript: 79: Expected a step # line 79, column 7.
pretty_json = status_json.toString(2)
According to last error message
groovy.lang.MissingMethodException:
No signature of method: java.lang.Class.prettyPrint()
is applicable for argument types: (net.sf.json.JSONObject)
You have net.sf.json.JSONObject in status_json variable.
that's really strange - seems you are getting status_json not in a standard way for jenkins
however according to documentation of this class
http://json-lib.sourceforge.net/apidocs/jdk15/net/sf/json/JSONObject.html#toString(int)
just do following to make pretty json:
def pretty_json = status_json.toString(2)
If you have Scripts not permitted to use method XYZ exception:
for security reasons a lot of non-standard methods are disabled in jenkins.
refer this answer to resolve this kind of issue: https://stackoverflow.com/a/39412951/1276664
and finally - almost every case from your question should work:
writeJSON( returnText: true, json: status_json ) :
update pipeline-utility-steps jenkins plugin to the latest version to support returnText parameter
the same as above
...
JsonOutput.toJson(status_json) : JsonOutput class located in groovy.json package. you could import this package at t
he beginning of the script import groovy.json or call it like this: groovy.json.JsonOutput.toJson(status_json). note that this method returns non-formatted json.
groovy.json.JsonOutput.prettyPrint(status_json) : check the documentation for JsonOutput.prettyPrint - it could be called for string and not for object. so this could work: groovy.json.JsonOutput.prettyPrint(status_json.toString()) but only in case when status_json.toString() returns a valid json and JsonOutput.prettyPrint allowed to be called in jenkins admin.
I just did a test and it gave results :
def pretty_json = writeJSON( returnText: true, json: status_json , pretty: 4)
Note : Ensure you have the plugin Pipeline Utility Steps installed. Or reinstall it again.
Below is the script example:
#!groovy
import hudson.model.Result
import groovy.json.*
pipeline
{
agent any
stages
{
stage ('Set up')
{
steps
{
script
{
hostname = "bld-machine"
reply_email = "jenkins#${hostname}.company.com"
actor_email = "user#company.com"
status_json = initStatusJson()
println (status_json)
}
}
}
stage ('Capture variables')
{
steps
{
script
{
// Added just for test
status_json.env["var"] = "Alt" as String
status_json.env["var2"] = "su" as String
println (status_json)
}
}
}
}
post {
always {
script {
def pretty_json = writeJSON( returnText: true, json: status_json , pretty: 4)
println (pretty_json)
emailext( subject: "CI/CD | ${currentBuild.currentResult}",
from: "${reply_email}",
to: "${actor_email}",
mimeType: "text/plain",
body: "${pretty_json}" )
}
}
}
}
def initStatusJson() {
def json_obj = readJSON text: '{}'
json_obj.job = readJSON text: '{}'
json_obj.env = [:]
json_obj.job.name = "${JOB_BASE_NAME}" as String
json_obj.job.number = "${BUILD_ID}" as String
json_obj.job.server = "${JENKINS_URL}" as String
json_obj.job.visualization = "${JENKINS_URL}/blue/organizations/jenkins/${JOB_BASE_NAME}/detail/${JOB_BASE_NAME}/${BUILD_ID}/pipeline" as String
return json_obj
}
Output log :

Jhipster gradle build 6.0.0 jdk-11 How to fix a failing build?

I created a project with JHipster 6.0.0-beta.0 and java version openjdk-11.0.2_windows-x64
I get the following error.
Task :bootRun FAILED
Error: Could not find or load main class com.jhipster.demo.desc.DescApp
Caused by: java.lang.NoClassDefFoundError: org/springframework/beans/factory/InitializingBean
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':bootRun'.
Process 'command 'C:\OpenJDK11\bin\java.exe'' finished with non-zero exit value 1
Here is my build.gradle file
import org.gradle.internal.os.OperatingSystem
buildscript {
repositories {
mavenLocal()
mavenCentral()
gradlePluginPortal()
maven { url "http://repo.spring.io/plugins-release" }
}
dependencies {
classpath "org.springframework.boot:spring-boot-gradle-plugin:${spring_boot_version}"
classpath "io.spring.gradle:propdeps-plugin:0.0.10.RELEASE"
//jhipster-needle-gradle-buildscript-dependency - JHipster will add additional gradle build script plugins here
}
}
plugins {
id "java"
id "maven"
id "war"
id "idea"
id "jacoco"
id "com.google.cloud.tools.jib" version "0.9.11"
id "com.gorylenko.gradle-git-properties" version "2.0.0"
id "net.ltgt.apt-eclipse" version "0.21"
id "net.ltgt.apt-idea" version "0.21"
id "net.ltgt.apt" version "0.21"
id "org.liquibase.gradle" version "2.0.1"
id "org.sonarqube" version "2.7"
//jhipster-needle-gradle-plugins - JHipster will add additional gradle plugins here
}
sourceCompatibility=1.8
targetCompatibility=1.8
assert System.properties["java.specification.version"] == "1.8" || "11" || "12"
apply plugin: "org.springframework.boot"
apply plugin: "propdeps"
apply from: "gradle/docker.gradle"
apply from: "gradle/sonar.gradle"
//jhipster-needle-gradle-apply-from - JHipster will add additional gradle scripts to be applied here
if (project.hasProperty("prod")) {
apply from: "gradle/profile_prod.gradle"
} else {
apply from: "gradle/profile_dev.gradle"
}
if (project.hasProperty("zipkin")) {
apply from: "gradle/zipkin.gradle"
}
idea {
module {
excludeDirs += files("node_modules")
}
}
eclipse {
sourceSets {
main {
java {
srcDirs += ["build/generated/source/apt/main"]
}
}
}
}
defaultTasks "bootRun"
group = "com.jhipster.demo.desc"
version = "0.0.1-SNAPSHOT"
description = ""
bootWar {
mainClassName = "com.jhipster.demo.desc.DescApp"
includes = ["WEB-INF/**", "META-INF/**"]
}
war {
enabled = true
extension = "war.original"
includes = ["WEB-INF/**", "META-INF/**"]
}
springBoot {
mainClassName = "com.jhipster.demo.desc.DescApp"
}
if (OperatingSystem.current().isWindows()) {
// https://stackoverflow.com/questions/40037487/the-filename-or-extension-is-too-long-error-using-gradle
task classpathJar(type: Jar) {
dependsOn configurations.runtime
appendix = "classpath"
doFirst {
manifest {
attributes "Class-Path": configurations.runtime.files.collect {
it.toURI().toURL().toString().replaceFirst(/file:\/+/, "/").replaceAll(" ", "%20")
}.join(" ")
}
}
}
bootRun {
dependsOn classpathJar
doFirst {
classpath = files("$buildDir/classes/java/main", "$buildDir/resources/main", classpathJar.archivePath)
}
}
}
test {
exclude "**/*IT*", "**/*IntTest*", "**/*CucumberIT*"
// uncomment if the tests reports are not generated
// see https://github.com/jhipster/generator-jhipster/pull/2771 and https://github.com/jhipster/generator-jhipster/pull/4484
// ignoreFailures true
reports.html.enabled = false
}
task integrationTest(type: Test) {
description = "Execute integration tests."
group = "verification"
include "**/*IT*", "**/*IntTest*"
exclude "**/*CucumberIT*"
// uncomment if the tests reports are not generated
// see https://github.com/jhipster/generator-jhipster/pull/2771 and https://github.com/jhipster/generator-jhipster/pull/4484
// ignoreFailures true
reports.html.enabled = false
}
task cucumberTest(type: Test) {
description = "Execute cucumber BDD tests."
group = "verification"
include "**/*CucumberIT*"
// uncomment if the tests reports are not generated
// see https://github.com/jhipster/generator-jhipster/pull/2771 and https://github.com/jhipster/generator-jhipster/pull/4484
// ignoreFailures true
reports.html.enabled = false
}
check.dependsOn cucumberTest
check.dependsOn integrationTest
task testReport(type: TestReport) {
destinationDir = file("$buildDir/reports/tests")
reportOn test
}
task integrationTestReport(type: TestReport) {
destinationDir = file("$buildDir/reports/tests")
reportOn integrationTest
}
task cucumberTestReport(type: TestReport) {
destinationDir = file("$buildDir/reports/tests")
reportOn cucumberTest
}
if (!project.hasProperty("runList")) {
project.ext.runList = "main"
}
project.ext.diffChangelogFile = "src/main/resources/config/liquibase/changelog/" + new Date().format("yyyyMMddHHmmss") + "_changelog.xml"
liquibase {
activities {
main {
driver "com.mysql.jdbc.Driver"
url "jdbc:mysql://localhost:3306/desc"
username "root"
password ""
changeLogFile "src/main/resources/config/liquibase/master.xml"
defaultSchemaName "desc"
logLevel "debug"
classpath "src/main/resources/"
}
diffLog {
driver "com.mysql.jdbc.Driver"
url "jdbc:mysql://localhost:3306/desc"
username "root"
password ""
changeLogFile project.ext.diffChangelogFile
referenceUrl "hibernate:spring:com.jhipster.demo.desc.domain?dialect=org.hibernate.dialect.MySQL5InnoDBDialect&hibernate.physical_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy&hibernate.implicit_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy"
defaultSchemaName "desc"
logLevel "debug"
classpath "$buildDir/classes/java/main"
}
}
runList = project.ext.runList
}
configurations {
providedRuntime
implementation.exclude module: "spring-boot-starter-tomcat"
}
repositories {
mavenLocal()
mavenCentral()
jcenter()
//jhipster-needle-gradle-repositories - JHipster will add additional repositories
}
dependencies {
// import JHipster dependencies BOM
implementation platform("io.github.jhipster:jhipster-dependencies:${jhipster_dependencies_version}" )
// Use ", version: jhipster_dependencies_version, changing: true" if you want
// to use a SNAPSHOT release instead of a stable release
implementation group: "io.github.jhipster", name: "jhipster-framework"
implementation "org.springframework.boot:spring-boot-starter-cache"
implementation "io.dropwizard.metrics:metrics-core"
implementation "io.micrometer:micrometer-registry-prometheus"
implementation "net.logstash.logback:logstash-logback-encoder"
implementation "com.fasterxml.jackson.datatype:jackson-datatype-hppc"
implementation "com.fasterxml.jackson.datatype:jackson-datatype-jsr310"
implementation "com.fasterxml.jackson.datatype:jackson-datatype-hibernate5"
implementation "com.fasterxml.jackson.core:jackson-annotations"
implementation "com.fasterxml.jackson.core:jackson-databind"
implementation "com.fasterxml.jackson.module:jackson-module-afterburner"
implementation "com.hazelcast:hazelcast"
implementation "com.hazelcast:hazelcast-hibernate53"
implementation "com.hazelcast:hazelcast-spring"
implementation "javax.cache:cache-api"
implementation "org.hibernate:hibernate-core"
implementation "com.zaxxer:HikariCP"
implementation "org.apache.commons:commons-lang3"
implementation "commons-io:commons-io"
implementation "javax.transaction:javax.transaction-api"
implementation "org.hibernate:hibernate-entitymanager"
implementation "org.hibernate:hibernate-envers"
implementation "org.hibernate.validator:hibernate-validator"
implementation "org.liquibase:liquibase-core"
liquibaseRuntime "org.liquibase:liquibase-core"
liquibaseRuntime "org.liquibase.ext:liquibase-hibernate5:${liquibase_hibernate5_version}"
liquibaseRuntime sourceSets.main.compileClasspath
implementation "org.springframework.boot:spring-boot-loader-tools"
implementation "org.springframework.boot:spring-boot-starter-mail"
implementation "org.springframework.boot:spring-boot-starter-logging"
implementation "org.springframework.boot:spring-boot-starter-actuator"
implementation "org.springframework.boot:spring-boot-starter-aop"
implementation "org.springframework.boot:spring-boot-starter-data-jpa"
implementation "org.springframework.boot:spring-boot-starter-data-elasticsearch"
// Spring Data Jest dependencies for Elasticsearch
implementation ("com.github.vanroy:spring-boot-starter-data-jest") {
exclude module: "commons-logging"
}
// log4j2-mock needed to create embedded elasticsearch instance with SLF4J
runtimeOnly "de.dentrassi.elasticsearch:log4j2-mock:0.0.1"
// end of Spring Data Jest dependencies
implementation "org.springframework.cloud:spring-cloud-stream"
implementation "org.springframework.cloud:spring-cloud-stream-binder-kafka"
implementation "org.springframework.kafka:spring-kafka"
implementation "org.springframework.boot:spring-boot-starter-security"
implementation ("org.springframework.boot:spring-boot-starter-web") {
exclude module: "spring-boot-starter-tomcat"
}
implementation "org.springframework.boot:spring-boot-starter-undertow"
implementation "org.springframework.boot:spring-boot-starter-thymeleaf"
implementation "org.zalando:problem-spring-web"
implementation "org.springframework.cloud:spring-cloud-starter"
implementation "org.springframework.cloud:spring-cloud-starter-netflix-ribbon"
implementation "org.springframework.cloud:spring-cloud-starter-netflix-hystrix"
implementation "org.springframework.retry:spring-retry"
implementation "org.springframework.cloud:spring-cloud-starter-netflix-eureka-client"
implementation "org.springframework.cloud:spring-cloud-starter-config"
implementation "org.springframework.cloud:spring-cloud-starter-openfeign"
implementation "org.springframework.boot:spring-boot-starter-cloud-connectors"
implementation "org.springframework.security:spring-security-config"
implementation "org.springframework.security:spring-security-data"
implementation "org.springframework.security:spring-security-web"
implementation "io.jsonwebtoken:jjwt-api"
runtimeOnly "io.jsonwebtoken:jjwt-impl"
runtimeOnly "io.jsonwebtoken:jjwt-jackson"
implementation ("io.springfox:springfox-swagger2") {
exclude module: "mapstruct"
}
implementation "io.springfox:springfox-bean-validators"
implementation "mysql:mysql-connector-java"
liquibaseRuntime "mysql:mysql-connector-java"
implementation "org.mapstruct:mapstruct:${mapstruct_version}"
annotationProcessor "org.mapstruct:mapstruct-processor:${mapstruct_version}"
annotationProcessor "org.hibernate:hibernate-jpamodelgen:${hibernate_version}"
annotationProcessor "org.glassfish.jaxb:jaxb-runtime:${jaxb_runtime_version}"
annotationProcessor ("org.springframework.boot:spring-boot-configuration-processor:${spring_boot_version}") {
exclude group: "com.vaadin.external.google", module: "android-json"
}
testImplementation "com.jayway.jsonpath:json-path"
testImplementation "io.cucumber:cucumber-junit"
testImplementation "io.cucumber:cucumber-spring"
testImplementation ("org.springframework.boot:spring-boot-starter-test") {
exclude group: "com.vaadin.external.google", module: "android-json"
}
testImplementation "org.springframework.security:spring-security-test"
testImplementation "org.springframework.boot:spring-boot-test"
testImplementation "org.assertj:assertj-core"
testImplementation "junit:junit"
testImplementation "org.mockito:mockito-core"
testImplementation "org.hamcrest:hamcrest-library"
testImplementation "com.h2database:h2"
testImplementation "org.springframework.cloud:spring-cloud-stream-test-support"
//jhipster-needle-gradle-dependency - JHipster will add additional dependencies here
}
task cleanResources(type: Delete) {
delete "build/resources"
}
wrapper {
gradleVersion = "5.3.1"
}
compileJava.dependsOn processResources
processResources.dependsOn bootBuildInfo
I would expect this to compile successfully.
Updated Gradle File (4/12/19)
import org.gradle.internal.os.OperatingSystem
buildscript {
repositories {
mavenLocal()
mavenCentral()
gradlePluginPortal()
maven { url "http://repo.spring.io/plugins-release" }
}
dependencies {
classpath "org.springframework.boot:spring-boot-gradle-plugin:${spring_boot_version}"
classpath "io.spring.gradle:propdeps-plugin:0.0.10.RELEASE"
**classpath "org.glassfish.jaxb:jaxb-runtime:${jaxb_runtime_version}"
classpath "javax.xml.bind:jaxb-api:${jaxb_api_version}"**
//jhipster-needle-gradle-buildscript-dependency - JHipster will add additional gradle build script plugins here
}
}
plugins {
id "java"
id "maven"
id "war"
id "idea"
id "jacoco"
id "com.google.cloud.tools.jib" version "0.9.11"
id "com.gorylenko.gradle-git-properties" version "2.0.0"
id "net.ltgt.apt-eclipse" version "0.21"
id "net.ltgt.apt-idea" version "0.21"
id "net.ltgt.apt" version "0.21"
id "org.liquibase.gradle" version "2.0.1"
id "org.sonarqube" version "2.7"
//jhipster-needle-gradle-plugins - JHipster will add additional gradle plugins here
}
**sourceCompatibility=1.11
targetCompatibility=1.11**
assert System.properties["java.specification.version"] == "1.8" || "11" || "12"
apply plugin: "org.springframework.boot"
apply plugin: "propdeps"
apply from: "gradle/docker.gradle"
apply from: "gradle/sonar.gradle"
//jhipster-needle-gradle-apply-from - JHipster will add additional gradle scripts to be applied here
if (project.hasProperty("prod")) {
apply from: "gradle/profile_prod.gradle"
} else {
apply from: "gradle/profile_dev.gradle"
}
if (project.hasProperty("zipkin")) {
apply from: "gradle/zipkin.gradle"
}
idea {
module {
excludeDirs += files("node_modules")
}
}
eclipse {
sourceSets {
main {
java {
srcDirs += ["build/generated/source/apt/main"]
}
}
}
}
defaultTasks "bootRun"
group = "com.jhipster.demo.descriptions"
version = "0.0.1-SNAPSHOT"
description = ""
bootWar {
mainClassName = "com.jhipster.demo.descriptions.DescriptionsApp"
includes = ["WEB-INF/**", "META-INF/**"]
}
war {
enabled = true
extension = "war.original"
includes = ["WEB-INF/**", "META-INF/**"]
}
springBoot {
mainClassName = "com.jhipster.demo.descriptions.DescriptionsApp"
}
if (OperatingSystem.current().isWindows()) {
// https://stackoverflow.com/questions/40037487/the-filename-or-extension-is-too-long-error-using-gradle
task classpathJar(type: Jar) {
dependsOn configurations.runtime
appendix = "classpath"
doFirst {
manifest {
attributes "Class-Path": configurations.runtime.files.collect {
it.toURI().toURL().toString().replaceFirst(/file:\/+/, "/").replaceAll(" ", "%20")
}.join(" ")
}
}
}
bootRun {
dependsOn classpathJar
doFirst {
classpath = files("$buildDir/classes/java/main", "$buildDir/resources/main", classpathJar.archivePath)
}
}
}
test {
exclude "**/*IT*", "**/*IntTest*", "**/*CucumberIT*"
// uncomment if the tests reports are not generated
// see https://github.com/jhipster/generator-jhipster/pull/2771 and https://github.com/jhipster/generator-jhipster/pull/4484
// ignoreFailures true
reports.html.enabled = false
}
task integrationTest(type: Test) {
description = "Execute integration tests."
group = "verification"
include "**/*IT*", "**/*IntTest*"
exclude "**/*CucumberIT*"
// uncomment if the tests reports are not generated
// see https://github.com/jhipster/generator-jhipster/pull/2771 and https://github.com/jhipster/generator-jhipster/pull/4484
// ignoreFailures true
reports.html.enabled = false
}
task cucumberTest(type: Test) {
description = "Execute cucumber BDD tests."
group = "verification"
include "**/*CucumberIT*"
// uncomment if the tests reports are not generated
// see https://github.com/jhipster/generator-jhipster/pull/2771 and https://github.com/jhipster/generator-jhipster/pull/4484
// ignoreFailures true
reports.html.enabled = false
}
check.dependsOn cucumberTest
check.dependsOn integrationTest
task testReport(type: TestReport) {
destinationDir = file("$buildDir/reports/tests")
reportOn test
}
task integrationTestReport(type: TestReport) {
destinationDir = file("$buildDir/reports/tests")
reportOn integrationTest
}
task cucumberTestReport(type: TestReport) {
destinationDir = file("$buildDir/reports/tests")
reportOn cucumberTest
}
if (!project.hasProperty("runList")) {
project.ext.runList = "main"
}
project.ext.diffChangelogFile = "src/main/resources/config/liquibase/changelog/" + new Date().format("yyyyMMddHHmmss") + "_changelog.xml"
liquibase {
activities {
main {
driver "com.mysql.jdbc.Driver"
url "jdbc:mysql://localhost:3306/descriptions"
username "root"
password ""
changeLogFile "src/main/resources/config/liquibase/master.xml"
defaultSchemaName "descriptions"
logLevel "debug"
classpath "src/main/resources/"
}
diffLog {
driver "com.mysql.jdbc.Driver"
url "jdbc:mysql://localhost:3306/descriptions"
username "root"
password ""
changeLogFile project.ext.diffChangelogFile
referenceUrl "hibernate:spring:com.jhipster.demo.descriptions.domain?dialect=org.hibernate.dialect.MySQL5InnoDBDialect&hibernate.physical_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy&hibernate.implicit_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy"
defaultSchemaName "descriptions"
logLevel "debug"
classpath "$buildDir/classes/java/main"
}
}
runList = project.ext.runList
}
configurations {
providedRuntime
implementation.exclude module: "spring-boot-starter-tomcat"
}
repositories {
mavenLocal()
mavenCentral()
jcenter()
//jhipster-needle-gradle-repositories - JHipster will add additional repositories
}
dependencies {
// import JHipster dependencies BOM
implementation platform("io.github.jhipster:jhipster-dependencies:${jhipster_dependencies_version}" )
// Use ", version: jhipster_dependencies_version, changing: true" if you want
// to use a SNAPSHOT release instead of a stable release
implementation group: "io.github.jhipster", name: "jhipster-framework"
implementation "org.springframework.boot:spring-boot-starter-cache"
implementation "io.dropwizard.metrics:metrics-core"
implementation "io.micrometer:micrometer-registry-prometheus"
implementation "net.logstash.logback:logstash-logback-encoder"
implementation "com.fasterxml.jackson.datatype:jackson-datatype-hppc"
implementation "com.fasterxml.jackson.datatype:jackson-datatype-jsr310"
implementation "com.fasterxml.jackson.datatype:jackson-datatype-hibernate5"
implementation "com.fasterxml.jackson.core:jackson-annotations"
implementation "com.fasterxml.jackson.core:jackson-databind"
implementation "com.fasterxml.jackson.module:jackson-module-afterburner"
implementation "com.hazelcast:hazelcast"
implementation "com.hazelcast:hazelcast-hibernate53"
implementation "com.hazelcast:hazelcast-spring"
implementation "javax.cache:cache-api"
implementation "org.hibernate:hibernate-core"
implementation "com.zaxxer:HikariCP"
implementation "org.apache.commons:commons-lang3"
implementation "commons-io:commons-io"
implementation "javax.transaction:javax.transaction-api"
implementation "org.hibernate:hibernate-entitymanager"
implementation "org.hibernate:hibernate-envers"
implementation "org.hibernate.validator:hibernate-validator"
implementation "org.liquibase:liquibase-core"
liquibaseRuntime "org.liquibase:liquibase-core"
liquibaseRuntime "org.liquibase.ext:liquibase-hibernate5:${liquibase_hibernate5_version}"
liquibaseRuntime sourceSets.main.compileClasspath
implementation "org.springframework.boot:spring-boot-loader-tools"
implementation "org.springframework.boot:spring-boot-starter-mail"
implementation "org.springframework.boot:spring-boot-starter-logging"
implementation "org.springframework.boot:spring-boot-starter-actuator"
implementation "org.springframework.boot:spring-boot-starter-aop"
implementation "org.springframework.boot:spring-boot-starter-data-jpa"
implementation "org.springframework.boot:spring-boot-starter-data-elasticsearch"
// Spring Data Jest dependencies for Elasticsearch
implementation ("com.github.vanroy:spring-boot-starter-data-jest") {
exclude module: "commons-logging"
}
// log4j2-mock needed to create embedded elasticsearch instance with SLF4J
runtimeOnly "de.dentrassi.elasticsearch:log4j2-mock:0.0.1"
// end of Spring Data Jest dependencies
implementation "org.springframework.cloud:spring-cloud-stream"
implementation "org.springframework.cloud:spring-cloud-stream-binder-kafka"
implementation "org.springframework.kafka:spring-kafka"
implementation "org.springframework.boot:spring-boot-starter-security"
implementation ("org.springframework.boot:spring-boot-starter-web") {
exclude module: "spring-boot-starter-tomcat"
}
implementation "org.springframework.boot:spring-boot-starter-undertow"
implementation "org.springframework.boot:spring-boot-starter-thymeleaf"
implementation "org.zalando:problem-spring-web"
implementation "org.springframework.cloud:spring-cloud-starter"
implementation "org.springframework.cloud:spring-cloud-starter-netflix-ribbon"
implementation "org.springframework.cloud:spring-cloud-starter-netflix-hystrix"
implementation "org.springframework.retry:spring-retry"
implementation "org.springframework.cloud:spring-cloud-starter-netflix-eureka-client"
implementation "org.springframework.cloud:spring-cloud-starter-config"
implementation "org.springframework.cloud:spring-cloud-starter-openfeign"
implementation "org.springframework.boot:spring-boot-starter-cloud-connectors"
implementation "org.springframework.security:spring-security-config"
implementation "org.springframework.security:spring-security-data"
implementation "org.springframework.security:spring-security-web"
implementation "io.jsonwebtoken:jjwt-api"
runtimeOnly "io.jsonwebtoken:jjwt-impl"
runtimeOnly "io.jsonwebtoken:jjwt-jackson"
implementation ("io.springfox:springfox-swagger2") {
exclude module: "mapstruct"
}
implementation "io.springfox:springfox-bean-validators"
implementation "mysql:mysql-connector-java"
liquibaseRuntime "mysql:mysql-connector-java"
implementation "org.mapstruct:mapstruct:${mapstruct_version}"
annotationProcessor "org.mapstruct:mapstruct-processor:${mapstruct_version}"
annotationProcessor "org.hibernate:hibernate-jpamodelgen:${hibernate_version}"
**implementation "javax.xml.bind:jaxb-api:${jaxb_api_version}"
annotationProcessor "javax.xml.bind:jaxb-api:${jaxb_api_version}"
implementation "org.glassfish.jaxb:jaxb-runtime:${jaxb_runtime_version}"
annotationProcessor "org.glassfish.jaxb:jaxb-runtime:${jaxb_runtime_version}"**
annotationProcessor ("org.springframework.boot:spring-boot-configuration-processor:${spring_boot_version}") {
exclude group: "com.vaadin.external.google", module: "android-json"
}
testImplementation "com.jayway.jsonpath:json-path"
testImplementation "io.cucumber:cucumber-junit"
testImplementation "io.cucumber:cucumber-spring"
testImplementation ("org.springframework.boot:spring-boot-starter-test") {
exclude group: "com.vaadin.external.google", module: "android-json"
}
testImplementation "org.springframework.security:spring-security-test"
testImplementation "org.springframework.boot:spring-boot-test"
testImplementation "org.assertj:assertj-core"
testImplementation "junit:junit"
testImplementation "org.mockito:mockito-core"
testImplementation "org.hamcrest:hamcrest-library"
testImplementation "com.h2database:h2"
testImplementation "org.springframework.cloud:spring-cloud-stream-test-support"
//jhipster-needle-gradle-dependency - JHipster will add additional dependencies here
}
task cleanResources(type: Delete) {
delete "build/resources"
}
wrapper {
gradleVersion = "5.3.1"
}
compileJava.dependsOn processResources
processResources.dependsOn bootBuildInfo
I believe you can fix this by adding JAXB to your build.gradle:
implementation 'org.glassfish.jaxb:jaxb-runtime'
If this works, please open an issue (or create a PR) in the JHipster project on GitHub.