Here is the build.gradle file. I have removed comments and sensitive data.
Still receiving the "missing EmbeddedServletContainerFactory Bean" error.
buildscript {
ext {
springBootVersion = '1.5.9.RELEASE'
}
repositories {
jcenter()
mavenCentral()
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
maven { url "https://plugins.gradle.org" }
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-
plugin:${springBootVersion}")
classpath("org.jfrog.buildinfo:build-info-extractor-gradle:4.5.4")
classpath("gradle.plugin.de.gliderpilot.gradle.semantic-
release:gradle-semantic-release-plugin:1.3.1")
}
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-jdbc')
compile('org.springframework.boot:spring-boot-starter-mail')
compile('org.springframework.boot:spring-boot-starter-thymeleaf')
{
exclude module: 'spring-boot-starter-tomcat'
}
runtime files ('/libs/ojdbc8.jar')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
plugins {
id "org.sonarqube" version "2.5"
id "com.gorylenko.gradle-git-properties" version "1.4.17"
id "de.gliderpilot.semantic-release" version "1.3.1"
}
apply plugin: 'java'
apply plugin: 'jacoco'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'idea'
apply plugin: 'com.jfrog.artifactory'
apply plugin: 'maven-publish'
sourceCompatibility = 1.8
group = 'com.usps.informed-delivery'
dependencies {
compile('org.springframework.boot:spring-boot-starter-activemq')
compile('org.springframework.boot:spring-boot-actuator-docs')
compile('org.springframework.boot:spring-boot-starter-aop')
compile('org.springframework.boot:spring-boot-starter-batch')
compile('org.springframework.boot:spring-boot-starter-cache')
compile('org.springframework.boot:spring-boot-starter-data-cassandra')
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('org.springframework.boot:spring-boot-starter-data-redis')
compile('org.springframework.boot:spring-boot-starter-integration')
compile('org.springframework.batch:spring-batch-integration')
compile('org.springframework.integration:spring-integration-xml')
compile('org.springframework.integration:spring-integration-mail')
compile('org.springframework.integration:spring-integration-test')
compile('org.slf4j:slf4j-api')
compile('org.springframework.integration:spring-integration-java-dsl')
compile("org.springframework:spring-oxm")
compile("joda-time:joda-time")
compile("com.fasterxml.jackson.dataformat:jackson-dataformat-xml")
compile("com.fasterxml.jackson.datatype:jackson-datatype-jsr310")
compile('org.liquibase:liquibase-core')
compile('libs/ojdbc8.jar')
runtime('org.springframework.boot:spring-boot-devtools')
runtime('com.h2database:h2')
testCompile('org.springframework.boot:spring-boot-starter-test')
testCompile('org.springframework.batch:spring-batch-test')
testCompile('org.springframework.integration:spring-integration-test')
}
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
}
}
}
artifactory {
contextUrl = 'http:whatever'
publish {
repository {
if (version.toString().endsWith("-SNAPSHOT")) {
repoKey = 'snapshots'
} else {
repoKey = 'releases'
}
username = ""
password = ""
}
defaults {
publications('mavenJava')
publishArtifacts = true
properties = ['qa.level': 'basic', 'dev.team': 'core']
publishPom = true
}
}
resolve {
repoKey = 'jcenter'
username = ""
password = ""
}
}
sonarqube {
properties {
property "sonar.sourceEncoding", "UTF-8"
property "sonar.projectKey", "readers-digest-generator"
property "sonar.projectName", "Readers Digest Generator"
}
}
Posting the build.gradle file per request. I have tried to resolve by putting
spring.main.web-environment-=false in aplication.properties file and app.setWebEnvironment(false) in BatchApplication.java
Spring Boot assumes it's a web app unless you configure it otherwise. The documentation (found here https://docs.spring.io/spring-boot/docs/current/reference/html/howto-spring-boot-application.html#howto-create-a-non-web-application) illustrates that you can either configure your application to not be a web app either programatically via calling SpringApplication#s setWebEnvironment(false) or via setting the property spring.main.web-environment=false
Related
I'm trying to publish a spring-boot project to local maven repository using Gradle. however, I'm getting below error.
My Gradle file looks like below
plugins {
id 'org.springframework.boot' version '2.3.8.RELEASE'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
id 'maven'
}
group = 'com.test'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
mavenLocal()
}
ext {
set('springCloudVersion', "Hoxton.SR9")
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.cloud:spring-cloud-starter-sleuth'
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}
test {
useJUnitPlatform()
}
Thanks,
I have changed the script to following and still it not working
below is the gradle tasks, error message and script
D:\workspaces\test\common>gradle clean publishToMavenLocal
> Task :publishMavenJavaPublicationToMavenLocal FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':publishMavenJavaPublicationToMavenLocal'.
> Failed to publish publication 'mavenJava' to repository 'mavenLocal'
> Artifact common-1.0.jar wasn't produced by this build.
* 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.
plugins {
id 'org.springframework.boot' version '2.3.8.RELEASE'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
id 'java-library'
id 'maven-publish'
}
group = 'com.test'
version = '1.0'
ext {
set('springCloudVersion', "Hoxton.SR9")
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
}
repositories {
mavenCentral()
}
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
versionMapping {
usage('java-api') {
fromResolutionOf('runtimeClasspath')
}
usage('java-runtime') {
fromResolutionResult()
}
}
}
}
repositories {
maven {
def releasesRepoUrl = "$buildDir/repos/releases"
def snapshotsRepoUrl = "$buildDir/repos/snapshots"
url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl
}
}
}
javadoc {
if(JavaVersion.current().isJava9Compatible()) {
options.addBooleanOption('html5', true)
}
}
however if remove dependencies, it's working fine
this script is working
plugins {
id 'java-library'
id 'maven-publish'
id 'signing'
}
group = 'com.example'
version = '1.0'
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
versionMapping {
usage('java-api') {
fromResolutionOf('runtimeClasspath')
}
usage('java-runtime') {
fromResolutionResult()
}
}
}
}
repositories {
maven {
def releasesRepoUrl = "$buildDir/repos/releases"
def snapshotsRepoUrl = "$buildDir/repos/snapshots"
url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl
}
}
}
javadoc {
if(JavaVersion.current().isJava9Compatible()) {
options.addBooleanOption('html5', true)
}
}
any idea why my script is not working ??
Thanks
I removed the org.springframework.boot plugin and used the below method to add dependencies and it worked. I would appreciate if someone can share if there is a document with this information.
this is the change I made
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
}
to
dependencies {
compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: '2.3.8.RELEASE'
}
and
plugins {
id 'org.springframework.boot' version '2.3.8.RELEASE'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
id 'java-library'
id 'maven-publish'
}
to
plugins {
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
id 'java-library'
id 'maven-publish'
}
build.gradle
buildscript {
ext {
springBootVersion = '2.0.6.RELEASE'
springRestDocsVersion = '2.0.2.RELEASE'
gradleDockerVersion = '1.2'
asciidoctorGradlePluginVersion = '1.5.9.2'
}
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath("org.asciidoctor:asciidoctor-gradle-plugin:${asciidoctorGradlePluginVersion}")
classpath("se.transmode.gradle:gradle-docker:${gradleDockerVersion}")
}
}
plugins {
id "org.springframework.boot" version "2.0.6.RELEASE"
id "org.asciidoctor.convert" version "1.5.9.2"
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'maven'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'org.asciidoctor.convert'
apply plugin: 'application'
apply plugin: 'docker'
apply from: 'local.gradle'
mainClassName = 'class.path.package.BootApplication'
version = '0.0.3a'
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
// Standard spring boot packages
compile('org.springframework.boot:spring-boot-starter-web')
compile('org.springframework.cloud:spring-cloud-starter-config')
compile('org.springframework.boot:spring-boot-starter-jersey')
compile('org.springframework.boot:spring-boot-starter-security')
compile('org.springframework.boot:spring-boot-starter-validation')
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('org.springframework.cloud:spring-cloud-starter-netflix-eureka-client')
compile('org.postgresql:postgresql')
compile('biz.paluch.redis:lettuce:4.4.6.Final')
compile('org.pacesys:openstack4j-core:3.1.0')
compile('org.pacesys.openstack4j.connectors:openstack4j-httpclient:3.1.0')
// Dozer object mapping
compile('net.sf.dozer:dozer:5.5.1')
// Sengrid library
compile('com.sendgrid:sendgrid-java:4.2.1')
compile('org.freemarker:freemarker:2.3.28')
// Cloudant
compile('com.cloudant:cloudant-client:2.9.0')
compile('com.squareup.okhttp3:okhttp-urlconnection:3.4.2')
compile('org.json:json:20171018')
compile('javax.validation:validation-api:2.0.1.Final')
//Swagger2
compile('io.springfox:springfox-swagger2:2.9.2')
compile('io.springfox:springfox-swagger-ui:2.9.2')
runtime('org.springframework.boot:spring-boot-devtools')
testCompile('org.springframework.boot:spring-boot-starter-test')
testCompile('org.springframework.security:spring-security-test')
testCompile("org.springframework.restdocs:spring-restdocs-mockmvc")
testCompile("org.asciidoctor:asciidoctor-gradle-plugin:1.5.9.2")
asciidoctor('org.springframework.restdocs:spring-restdocs-asciidoctor:2.0.2.RELEASE')
}
processResources {
// expand(project.properties)
}
ext {
springCloudVersion = 'Finchley.RELEASE'
snippetsDir = file('build/generated-snippets')
// springRestDocsVersion = '2.0.2.RELEASE'
}
ext['spring-restdocs.version'] = '${springRestDocsVersion}'
test {
outputs.dir snippetsDir
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
mavenBom("org.springframework.boot:spring-boot-dependencies:${springBootVersion}")
}
}
asciidoctor {
// attributes "snippets": snippetsDir
inputs.dir snippetsDir
dependsOn test
}
jar {
dependsOn asciidoctor
from ('${asciidoctor.outputDir}/html5') {
into 'static/apidocs'
}
}
my problem actually in this part:
jar {
dependsOn asciidoctor
from ('${asciidoctor.outputDir}/html5') {
into 'static/apidocs'
}
}
executed jar doesn't copy index.html file executed from asciidoctor into jar and jar executed only without this file
So how i can copy build/asciidoc/html5/index.html from build
folder into executed jar?
Also if i need to use bootJar task so how i can make it include all jar needed into /BOOT-INF/lib/
Your configuration is almost right, but you are customising the wrong task. A Spring Boot fat jar is built with the bootJar task rather than the jar task.
You need to replace jar with bootJar in your build.gradle. This will result in it looking the same as the following example:
bootJar {
dependsOn asciidoctor
from ("${asciidoctor.outputDir}/html5") {
into 'static/docs'
}
}
This is the configuration that's described in the REST Docs documentation.
I have a multibuild project and I am currently just setting it up. Each module naturally each has a gradle.build file that only contains the following:
dependencies {
}
In the main build.gradle file I have want is needed for every module. However when I do a gradle build I get a error saying:
Cannot resolve external dependency org.springframework.boot:spring-boot-starter: because no repositories
are defined. Required by:
project :
apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'io.spring.dependency-management'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
buildscript {
ext {
springBootVersion = '2.0.0.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
sourceSets.all { ext.purpose = null }
// Everything in subprojects are applied to all modules
subprojects {
apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
version = '0.0.1-SNAPSHOT'
test {
useTestNG()
testLogging.showStandardStreams = true
beforeTest { descriptor ->
logger.lifecycle("Running test: " + descriptor)
}
// listen to standard out and standard error of the test JVM(s)
onOutput { descriptor, event ->
logger.lifecycle("Test: " + descriptor + " produced standard out/err: " + event.message )
}
}
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
repositories {
jcenter()
mavenCentral()
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
compile('org.springframework.boot:spring-boot-starter')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
}
dependencies {
compile('org.springframework.boot:spring-boot-starter')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
Advice
You've defined repositories for subprojects only, but you have to define it in the root project too, because you have a dependencies block there:
dependencies {
compile('org.springframework.boot:spring-boot-starter')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
In your case you can do it by declaring repositories once more out of the subprojects closure:
repositories {
jcenter()
mavenCentral()
maven {
url "https://plugins.gradle.org/m2/"
}
}
subprojects {
...
}
Or you can define it for all projects:
allprojects {
repositories {
jcenter()
mavenCentral()
maven {
url "https://plugins.gradle.org/m2/"
}
}
}
in that case, you don't need o declare it in subprojects closure
I fixed in Intellij IDEA with these steps.
Go to Settings->Gradle
Under 'Use Gradle from' provide the correct version of Gradle
Gradle JVM I selected as local JAVA_HOME
What is the build.gradle.kts version of the the following Gradle script?
apply plugin: 'maven'
apply plugin: 'java'
sourceCompatibility = 7
targetCompatibility = 7
dependencies {
compile 'com.google.guava:guava:13.0.1'
compile 'joda-time:joda-time:2.1'
testCompile 'junit:junit:4.11'
testCompile 'org.mockito:mockito-core:1.9.5'
}
task writeNewPom << {
pom {
project {
groupId 'org.example'
artifactId 'test'
version '1.0.0'
inceptionYear '2008'
licenses {
license {
name 'The Apache Software License, Version 2.0'
url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
distribution 'repo'
}
}
}
}.writeTo("$buildDir/newpom.xml")
}
References
1- Gradle sample was here.
I believe this is the same as a build.gradle.kts file:
plugins {
java
maven
}
java {
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
}
repositories {
jcenter()
}
dependencies {
compile("com.google.guava:guava:13.0.1")
compile("joda-time:joda-time:2.1")
testCompile("junit:junit:4.11")
testCompile("org.mockito:mockito-core:1.9.5")
}
tasks {
"writeNewPom" {
doLast {
project.the<MavenPluginConvention>().pom {
project {
groupId = "org.example"
artifactId = "test"
version = "1.0.0"
withGroovyBuilder {
"inceptionYear"("2008")
"licenses" {
"license" {
"name"("The Apache Software License, Version 2.0")
"url"("http://www.apache.org/licenses/LICENSE-2.0.txt")
"distribution"("repo")
}
}
}
}
}.writeTo("$buildDir/newPom.xml")
}
}
}
You have to use the withGroovyBuilder method to add the untyped properties to the model
I am trying to implement sonar with gradle for code-coverage measure for my project.
we are using gradle-4.0.1 and sonarqube-6.4 .
when I run gradle sonarqube from command line I get this error-
Plugin with id 'org.sonarqube' not found.
I tried few code changes but no luck, please help.
My build.gradle file is as below-
buildscript {
ext {
springBootVersion = '1.5.4.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'org.sonarqube'
apply plugin: "jacoco"
apply plugin: "java"
apply plugin: "war"
apply plugin: "org.springframework.boot"
sonarqube {
properties {
property "sonar.projectName","Spring4WebService Code Coverage Demo"
property "sonar.projectKey", "org.sonarqubeJacocoCodeCoverage"
property "sonar.reportPath" , "${project.buildDir}/jacoco/test.exec"
}
}
test{
ignoreFailures = true
}
ext {
jacocoVersion = '0.7.6.201602180812'
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
}
sourceSets {
main.java.srcDir "src/main/java"
test.java.srcDir "src/test/java"
}
springBoot {
mainClass = "com.concretepage.config.WebAppInitializer"
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-web','com.fasterxml.jackson.core:jackson-databind')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
jacoco{
toolVersion = "${jacocoVersion}"
}
jacocoTestReport {
reports{
html.enabled=true
xml.enabled=true
csv.enabled=true
}
}
Just like the 'org.springframework.boot' plugin, the 'org.sonarqube' plugin does not belong to Gradle. It is a third-party plugin, so you need to add it as a buildscript dependency:
buildscript {
ext {
springBootVersion = '1.5.4.RELEASE'
}
repositories {
mavenCentral()
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.5"
}
}
Now apply plugin: 'org.sonarqube' should work fine.
In my case it looks like:
plugins {
id 'groovy'
id 'application'
id 'org.sonarqube' version '3.0'
}
repositories {
mavenCentral()
}
sonarqube {
properties {
property "sonar.host.url", "http://sonarqube:9000"
property "sonar.sources", "src"
}
}
tasks['sonarqube'].dependsOn test
Using the plugins DSL specifying a full version (e.g., id "org.sonarqube" version "3.5.0.2730" instead of id "org.sonarqube" version "3.5.0") in the plugins section of build.gradle resolved this issue for me.
Here are examples for plugins DSL and legacy plugin application: https://plugins.gradle.org/plugin/org.sonarqube