Enforcing the order of deployment in gradle - java

This is my build.gradle file
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath 'com.moowork.gradle:gradle-grunt-plugin:0.13'
classpath "gradle.plugin.com.github.scobal.eslint:gradle-eslint-plugin:1.0.1"
}
}
plugins{
id "com.moowork.grunt" version "0.13"
id "com.moowork.node" version "0.13"
}
// apply all plug-ins
apply plugin: 'com.moowork.grunt'
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'war'
apply plugin: "com.github.scobal.eslint"
sourceCompatibility = 1.8
//version = '24.1.1.0'
war.doFirst{
deleteFiles()
grunt_build()
grunt_compile()
}
task deleteFiles(type: Delete){
delete fileTree("${System.properties['TOMCAT_HOME']}/webapps"){
include '**/*.war'
}
}
task deployToTomcat(type: Copy) {
from war.archivePath
into "${System.properties['TOMCAT_HOME']}/webapps"
}
deployToTomcat.doFirst{
war()
}
clean.doFirst{
deleteFiles
}
eslint {
inputs = ["./src/**/*.js"]
}
// exclude the files we don't want to deliver
// TODO - is there an easier way to exclude all directories under js??? We don't want any of them.
war {
exclude('src/js/main.js')
exclude('src/js/actions')
exclude('src/js/api')
exclude('src/js/components')
exclude('src/js/constants')
exclude('src/js/dispatcher')
exclude('src/js/stores')
}
jar {
manifest {
attributes 'Implementation-Title': 'Gradle Quickstart' //,
//'Implementation-Version': version
}
}
repositories {
mavenCentral()
}
dependencies {
compile group: 'commons-collections', name: 'commons-collections', version: '3.2'
compile("org.springframework:spring-webmvc:4.0.3.RELEASE")
compile("com.fasterxml.jackson.core:jackson-core:2.7.4")
compile("com.fasterxml.jackson.core:jackson-annotations:2.7.4")
compile("com.fasterxml.jackson.core:jackson-databind:2.7.4")
compile("org.darkphoenixs:log4j:1.2.17")
compile files('libs/opla230.jar')
testCompile group: 'junit', name: 'junit', version: '4.+'
}
test {
systemProperties 'property': 'value'
}
uploadArchives {
repositories {
flatDir {
dirs 'repos'
}
}
}
The problem that's happening is that the deployToTomcat is running first and deploying an old war on the tomcat. After that the war task of the war plugin runs and generates a new war which never gets deployed. Can someone help me with the enforcing of the order of these actions.

You need to add "dependsOn war" in your deployToTomcat task.

Related

copying dependencies to libs folder in gradle

I am trying to copy all the dependencies to libs folder, but it isn't working with the copyDependency task. I've tried few tweaks with the task, however it won't copy. Below is my build.gradle file
plugins {
id 'java'
id 'maven-publish'
}
repositories {
mavenLocal()
maven {
url = uri('https://repo.maven.apache.org/maven2/')
}
}
dependencies {
compile 'org.springframework.boot:spring-boot-starter-batch:2.0.2.RELEASE'
compile 'org.springframework.boot:spring-boot-starter-jdbc:2.0.2.RELEASE'
compile 'org.springframework.boot:spring-boot-starter-web:2.0.2.RELEASE'
compile 'org.springframework.boot:spring-boot-starter-actuator:2.0.2.RELEASE'
compile 'org.postgresql:postgresql:42.2.2'
compile 'com.h2database:h2:1.4.197'
compile 'com.amazonaws:aws-java-sdk:1.11.290'
compile 'org.spockframework:spock-core:1.0-groovy-2.4'
compile 'org.codehaus.groovy:groovy-all:2.4.1'
compile 'com.github.ulisesbocchio:jasypt-spring-boot-starter:1.15'
testImplementation 'org.springframework.boot:spring-boot-starter-test:2.0.2.RELEASE'
testImplementation 'org.springframework.batch:spring-batch-test:4.0.1.RELEASE'
}
group = 'com.loyalty.finance'
description = 'Spring Boot and batch integrated project for fin-issuance-processor'
java.sourceCompatibility = JavaVersion.VERSION_1_8
publishing {
publications {
maven(MavenPublication) {
from(components.java)
}
}
}
task copyDependencies(type: Copy) {
from configurations.runtime
into 'libs'
}
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}

multi-module Gradle project: webjar doesn't get placed in "META-INF/resources"

I am trying to combine a Spring Boot backend api and a React frontend app into one single jar.
I was able to build a jar file containing both by following this article (https://medium.com/xebia-engineering/a-minimalistic-guide-to-building-and-deploying-monolithic-spring-boot-react-applications-39440035b27) but the frontend jar ends up in BOOT-INF/lib/frontend.jar instead of META-INF/resources. How can I create a jar file with the webjar in the right directory so it can render a React page?
frontend/build.gradle
plugins {
id "com.moowork.node" version "1.3.1"
}
apply plugin: "java"
apply plugin: "com.moowork.node"
node {
version = "12.9.1"
download = true
}
task bundle(type: NpmTask, dependsOn: npmInstall) {
args = ["run", "build"]
}
task uiTest(type: NpmTask) {
environment = ["CI": "true"]
args = ["run", "test"]
}
task run(type: NpmTask) {
args = ["start"]
}
check.dependsOn(test)
jar.dependsOn(bundle)
task webjar(type: Jar) {
from(fileTree("build")) {
into "META-INF/resources"
}
}
check.dependsOn(test)
jar.dependsOn(bundle)
jar.finalizedBy("webjar")
backend/build.gradle
plugins {
id 'org.springframework.boot' version '2.1.5.RELEASE'
id 'java'
}
apply plugin: 'io.spring.dependency-management'
apply plugin: 'maven'
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
repositories {
mavenCentral()
maven {
url 'https://repo.spring.io/libs-milestone'
}
}
jar {
manifest {
attributes "Main-Class": "com.example.kasahararestapi.StockCheckAppApplication"
}
from {
configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
}
}
tasks.withType(Test) {
scanForTestClasses = false
include "**/*Test.class" // whatever Ant pattern matches your test class files
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-security'
runtimeOnly 'org.springframework.boot:spring-boot-devtools'
runtimeOnly 'mysql:mysql-connector-java'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
implementation 'org.springframework.social:spring-social-github:1.0.0.M4'
implementation 'commons-io:commons-io:2.6'
implementation 'org.apache.commons:commons-lang3:3.0'
implementation 'io.jsonwebtoken:jjwt:0.9.0'
implementation platform('com.amazonaws:aws-java-sdk-bom:1.11.807')
implementation 'com.amazonaws:aws-java-sdk-s3'
implementation 'org.springframework.boot:spring-boot-starter-mail:1.2.0.RELEASE'
implementation 'org.modelmapper:modelmapper:2.3.5'
testCompile group: 'junit', name: 'junit', version: '4.11'
implementation project(path: ':frontend', configuration: 'default')
}
setting.gradle
pluginManagement {
repositories {
gradlePluginPortal()
}
}
rootProject.name = 'stock_check_app'
include 'backend'
include 'frontend'

trying to get the war file from Jhipster project

i'm trying to get the war file from Jhipster project project using this command
./gradlew -Pprod -Pwar clean bootWar
this the error that i got
FAILURE: Build failed with an exception.
What went wrong:
Task 'bootWar' not found in root project 'account'. Some candidates are: 'bootRun'.
Try:
Run gradlew tasks to get a list of available tasks. 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
this my bild.gradle
import org.gradle.internal.os.OperatingSystem
buildscript {
repositories {
mavenLocal()
jcenter()
maven { url "https://repo.spring.io/plugins-release" }
maven { url "https://plugins.gradle.org/m2/" }
}
dependencies {
classpath "org.springframework.boot:spring-boot-gradle-plugin:${spring_boot_version}"
classpath "io.spring.gradle:propdeps-plugin:0.0.9.RELEASE"
classpath "gradle.plugin.com.gorylenko.gradle-git-properties:gradle-git-properties:1.4.17"
//jhipster-needle-gradle-buildscript-dependency - JHipster will add additional gradle build script plugins here
}
}
plugins {
id "org.sonarqube" version "2.5"
id "net.ltgt.apt-eclipse" version "0.13"
id "net.ltgt.apt-idea" version "0.13"
id "net.ltgt.apt" version "0.13"
id "io.spring.dependency-management" version "1.0.3.RELEASE"
//jhipster-needle-gradle-plugins - JHipster will add additional gradle plugins here
}
apply plugin: 'java'
sourceCompatibility=1.8
targetCompatibility=1.8
tasks.withType(JavaExec) {
jvmArgs = [ '-Xmx512m','-Xms256m']
}
// Until JHipster supports JDK 9
assert System.properties['java.specification.version'] == '1.8'
apply plugin: 'maven'
apply plugin: 'org.springframework.boot'
apply plugin: 'war'
apply plugin: 'propdeps'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'idea'
dependencyManagement {
imports {
mavenBom 'io.github.jhipster:jhipster-dependencies:' + jhipster_dependencies_version
//jhipster-needle-gradle-dependency-management - JHipster will add additional dependencies management here
}
}
defaultTasks 'bootRun'
group = 'com.skywriter.account'
version = '0.0.1-SNAPSHOT'
description = ''
bootRepackage {
mainClass = 'com.skywriter.account.AccountApp'
}
war {
}
springBoot {
mainClass = 'com.skywriter.account.AccountApp'
executable = true
buildInfo()
}
if (OperatingSystem.current().isWindows()) {
task pathingJar(type: Jar) {
dependsOn configurations.runtime
appendix = 'pathing'
doFirst {
manifest {
attributes 'Class-Path': configurations.runtime.files.collect {
it.toURI().toURL().toString().replaceFirst(/file:\/+/, '/').replaceAll(' ', '%20')
}.join(' ')
}
}
}
bootRun {
addResources = false
dependsOn pathingJar
doFirst {
classpath = files("$buildDir/classes/java/main", "$buildDir/resources/main", pathingJar.archivePath)
}
}
} else {
bootRun {
addResources = false
}
}
test {
exclude '**/CucumberTest*'
// 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 '**/CucumberTest*'
// 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
task testReport(type: TestReport) {
destinationDir = file("$buildDir/reports/tests")
reportOn test
}
task cucumberTestReport(type: TestReport) {
destinationDir = file("$buildDir/reports/tests")
reportOn cucumberTest
}
apply from: 'gradle/docker.gradle'
apply from: 'gradle/sonar.gradle'
apply from: 'gradle/liquibase.gradle'
apply from: 'gradle/mapstruct.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'
}
if (project.hasProperty('stage')) {
apply from: 'gradle/profile_stage.gradle'
}
if (project.hasProperty('demo')) {
apply from: 'gradle/profile_demo.gradle'
}
if (project.hasProperty('aws')) {
apply from: 'gradle/profile_aws.gradle'
}
if (project.hasProperty('devtest')) {
apply from: 'gradle/profile_devtest.gradle'
}
if (project.hasProperty('aws')) {
apply from: 'gradle/profile_aws.gradle'
}
else {
apply from: 'gradle/profile_dev.gradle'
}
if (project.hasProperty('graphite')) {
apply from: 'gradle/graphite.gradle'
}
if (project.hasProperty('prometheus')) {
apply from: 'gradle/prometheus.gradle'
}
if (project.hasProperty('zipkin')) {
apply from: 'gradle/zipkin.gradle'
}
configurations {
providedRuntime
compile.exclude module: "spring-boot-starter-tomcat"
}
repositories {
mavenLocal()
jcenter()
}
dependencies {
compile 'io.logz.logback:logzio-logback-appender:v1.0.21'
compile "org.springframework.boot:spring-boot-starter-cache"
compile "io.github.jhipster:jhipster"
compile "io.dropwizard.metrics:metrics-core"
compile "io.dropwizard.metrics:metrics-json"
compile "io.dropwizard.metrics:metrics-jvm"
compile "io.dropwizard.metrics:metrics-servlet"
compile "io.dropwizard.metrics:metrics-servlets"
compile "net.logstash.logback:logstash-logback-encoder"
compile "com.fasterxml.jackson.datatype:jackson-datatype-json-org"
compile "com.fasterxml.jackson.datatype:jackson-datatype-hppc"
compile "com.fasterxml.jackson.datatype:jackson-datatype-jsr310"
compile "com.fasterxml.jackson.datatype:jackson-datatype-hibernate5"
compile "com.fasterxml.jackson.core:jackson-annotations"
compile "com.fasterxml.jackson.core:jackson-databind"
compile "com.fasterxml.jackson.module:jackson-module-afterburner"
compile "com.ryantenney.metrics:metrics-spring"
compile "com.hazelcast:hazelcast"
compile "com.hazelcast:hazelcast-hibernate52"
compile "com.hazelcast:hazelcast-spring"
compile "javax.cache:cache-api"
compile "org.hibernate:hibernate-core"
compile "com.zaxxer:HikariCP"
compile "org.apache.commons:commons-lang3"
compile "commons-io:commons-io"
compile "javax.transaction:javax.transaction-api"
compile "org.hibernate:hibernate-entitymanager"
compile "org.hibernate:hibernate-envers"
compile "org.hibernate:hibernate-validator"
compile "org.liquibase:liquibase-core"
compile "com.mattbertolini:liquibase-slf4j"
compile "org.springframework.boot:spring-boot-actuator"
compile "org.springframework.boot:spring-boot-autoconfigure"
compile "org.springframework.boot:spring-boot-loader-tools"
compile "org.springframework.boot:spring-boot-starter-mail"
compile "org.springframework.boot:spring-boot-starter-logging"
compile "org.springframework.boot:spring-boot-starter-aop"
compile "org.springframework.boot:spring-boot-starter-data-jpa"
compile "org.springframework.boot:spring-boot-starter-security"
compile ("org.springframework.boot:spring-boot-starter-web") {
exclude module: 'spring-boot-starter-tomcat'
}
compile "org.springframework.boot:spring-boot-starter-undertow"
compile "org.springframework.boot:spring-boot-starter-thymeleaf"
compile "org.zalando:problem-spring-web"
compile "org.springframework.cloud:spring-cloud-starter"
compile "org.springframework.cloud:spring-cloud-starter-ribbon"
compile "org.springframework.cloud:spring-cloud-starter-hystrix"
compile "org.springframework.cloud:spring-cloud-starter-spectator"
compile "org.springframework.retry:spring-retry"
compile "org.springframework.cloud:spring-cloud-starter-eureka"
compile "org.springframework.cloud:spring-cloud-starter-config"
compile "org.springframework.cloud:spring-cloud-security"
compile "org.springframework.cloud:spring-cloud-starter-feign"
compile "org.springframework.cloud:spring-cloud-spring-service-connector"
compile "org.springframework:spring-context-support"
compile "org.springframework.security:spring-security-config"
compile "org.springframework.security:spring-security-data"
compile "org.springframework.security:spring-security-web"
compile "org.springframework.security.oauth:spring-security-oauth2"
compile "org.springframework.security:spring-security-jwt"
compile ("io.springfox:springfox-swagger2") {
exclude module: 'mapstruct'
}
compile "io.springfox:springfox-bean-validators"
compile "org.postgresql:postgresql"
compile "org.mapstruct:mapstruct-jdk8:${mapstruct_version}"
testCompile "com.jayway.jsonpath:json-path"
testCompile "info.cukes:cucumber-junit"
testCompile "info.cukes:cucumber-spring"
testCompile ("org.springframework.boot:spring-boot-starter-test") {
exclude group: 'com.vaadin.external.google', module: 'android-json'
}
testCompile "org.springframework.security:spring-security-test"
testCompile "org.springframework.boot:spring-boot-test"
testCompile "org.assertj:assertj-core"
testCompile "junit:junit"
testCompile "org.mockito:mockito-core"
testCompile "com.mattbertolini:liquibase-slf4j"
testCompile "org.hamcrest:hamcrest-library"
testCompile "com.h2database:h2"
optional ("org.springframework.boot:spring-boot-configuration-processor") {
exclude group: 'com.vaadin.external.google', module: 'android-json'
}
//jhipster-needle-gradle-dependency - JHipster will add additional dependencies here
}
task cleanResources(type: Delete) {
delete 'build/resources'
}
task wrapper(type: Wrapper) {
gradleVersion = '4.4'
}
task stage(dependsOn: 'bootRepackage') {
}
compileJava.dependsOn processResources
processResources.dependsOn cleanResources,bootBuildInfo
bootBuildInfo.mustRunAfter cleanResources
thanks in advance
To make the answer more visible (valid for jhipster 4.x):
for creating a war that can be deployed in an application server use ./gradlew war and for an executable war file, which can be executed via java -jar use ./gradlew bootWar.

ProtoBuffer files generated after building project missing dependencies

I am trying to create implement client-server communication with the help of grpc
proto file -
syntax="proto3";
package com.project.grpc.roleservice;
message UserRequest {
string userName=1;
}
message RoleReply {
string userRole=1;
}
service UserRoleFromServer{
rpc getRoleUser(stream UserRequest) returns (stream RoleReply);
}
Gradle build -
buildscript {
ext {
springBootVersion = '2.0.4.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath("com.google.protobuf:protobuf-gradle-plugin:0.8.5")
}
}
plugins {
id 'java'
}
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'com.google.protobuf'
group 'com.project.grpc.roleservice'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
protobuf {
protoc {
artifact = "com.google.protobuf:protoc:3.5.1-1"
}
plugins {
grpc {
artifact = 'io.grpc:protoc-gen-grpc-java:1.16.1'
}
}
generateProtoTasks {
all()*.plugins {
grpc {}
}
}
}
repositories {
mavenCentral()
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('org.springframework.boot:spring-boot-starter-web')
compile( 'io.grpc:grpc-netty-shaded:1.16.1')
compile('io.grpc:grpc-protobuf:1.16.1')
compile('io.grpc:grpc-stub:1.16.1')
compile 'io.github.lognet:grpc-spring-boot-starter:3.0.0'
runtime('org.springframework.boot:spring-boot-devtools')
runtime('mysql:mysql-connector-java')
testCompile (group: 'junit', name: 'junit', version: '4.12')
}
After building the project all the files are generated in a build folder and a UserRoleFromServerGrpc is generated which I want to extend and implement in my server-service file
But The UserRoleFromServerGrpc has a lot of errors it asks for following dependencies
Streamobserver needs io.grpc:grpc-stub:1.16.1 ,grpc-core
Add io.grpc:grpc-stub:1.16.1 to classpath
but I have already defined these dependencies in gradle build
How to resolve this issue
Screenshot of IDE

spring boot - No auto configuration found in META-INF/spring.factories - gradle

I am creating javafx app with spring boot in background. To do this I used this library: springboot-javafx-support Every time when I start it I get exception "No auto configuration found in META-INF/spring.factories". I have no idea what I am doing wrong. I guess it must be something wrong in my gradle build script.
Below you can find gradle.build file
buildscript {
ext {
springBootVersion = '2.0.1.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
//apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
group = 'pl.opfol.subiekt'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.9
sourceSets {
main.java.srcDirs += 'build/generated/source/apt/main'
}
jar {
enabled = true
}
bootJar {
mainClassName = 'pl.opfol.subiekt.util.MainApp'
}
repositories {
mavenCentral()
maven {
url "https://artifact.aspose.com/repo"
}
maven {
url "https://dl.bintray.com/jerady/maven"
}
}
dependencies {
compile 'org.projectlombok:lombok:1.16.20'
compile('org.springframework.boot:spring-boot-starter')
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('org.springframework.boot:spring-boot-starter-validation')
compile('org.springframework.boot:spring-boot-starter-logging')
compile('com.h2database:h2:1.4.197')
compile('javax.mail:javax.mail-api:1.6.1')
compile('com.sun.mail:javax.mail:1.6.1')
compile('commons-io:commons-io:2.6')
compile('commons-codec:commons-codec:1.11')
compile('org.apache.commons:commons-collections4:4.1')
compile('org.apache.commons:commons-lang3:3.7')
compile('commons-configuration:commons-configuration:1.10')
compile('com.aspose:aspose-words:17.3.0:jdk16')
compile('com.microsoft.sqlserver:mssql-jdbc:6.4.0.jre9')
compile('javax.annotation:javax.annotation-api:1.3.2')
compile('org.controlsfx:controlsfx:9.0.0')
compile('com.itextpdf:itext7-core:7.1.1')
compile('javax.xml.bind:jaxb-api:2.3.0')
compile('com.jfoenix:jfoenix:9.0.0')
compile('de.roskenet:springboot-javafx-support:2.1.6')
compile('de.jensd:fontawesomefx-controls:9.1.2')
compile('de.jensd:fontawesomefx-commons:9.1.2')
compile('de.jensd:fontawesomefx-weathericons:2.0.10-9.1.2')
compile('de.jensd:fontawesomefx-materialicons:2.2.0-9.1.2')
compile('de.jensd:fontawesomefx-materialdesignfont:2.0.26-9.1.2')
compile('de.jensd:fontawesomefx-octicons:4.3.0-9.1.2')
compile('de.jensd:fontawesomefx-fontawesome:4.7.0-9.1.2')
compile('de.jensd:fontawesomefx-materialstackicons:2.1-5-9.1.2')
compile('de.jensd:fontawesomefx-icons525:4.2.0-9.1.2')
compile('de.jensd:fontawesomefx-emojione:3.1.1-9.1.2')
compileOnly ('org.hibernate:hibernate-jpamodelgen:5.2.16.Final')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
I had same problem, make sure you run it on JRE 1.8.

Categories

Resources