when I import spring cloud mavenBom,if I use code:
subprojects {
apply plugin: 'java'
apply plugin: 'io.spring.dependency-management'
ext {
springCloudVersion = "Hoxton.SR8"
}
repositories {
maven { url 'https://maven.aliyun.com/repository/public/' }
mavenLocal()
mavenCentral()
}
dependencyManagement{
dependencies {
dependency(group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: '2.3.7.RELEASE'){
exclude group: 'log4j', name: 'log4j', version: '1.2.16'
}
dependency(group: 'log4j', name: 'log4j', version: '1.2.17')
dependency('org.projectlombok:lombok:1.18.2')
}
imports {
mavenBom 'org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}'
}
}
}
it doesn't work, and the error is :
Could not find org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}.
if I transform ${springCloudVersion} to Hoxton.SR8,it work absolutely.
so, what result in this case?
If you want ${springCloudVersion} to be interpreted, you need a GString (use double quote ")
https://groovy-lang.org/syntax.html#_double_quoted_string
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
Related
I want to display static pages using Spring Boot. I tried this configuration:
plugins {
id "java"
id "org.asciidoctor.jvm.convert" version "3.3.2"
}
repositories {
maven { url 'https://repo.spring.io/milestone' }
maven { url 'https://repo.spring.io/snapshot' }
mavenCentral()
mavenLocal()
}
group = 'com.example'
sourceCompatibility = 11
targetCompatibility = 11
ext {
restdocsVersion = '3.0.0-SNAPSHOT'
snippetsDir = file('src/static/docs')
}
configurations {
asciidoctorExtensions
}
dependencies {
asciidoctorExtensions "org.springframework.restdocs:spring-restdocs-asciidoctor:$restdocsVersion"
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: '2.6.3'
implementation 'io.projectreactor.netty:reactor-netty-http:1.0.15'
testImplementation 'io.rest-assured:rest-assured:4.5.0'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.0'
testImplementation "org.springframework.restdocs:spring-restdocs-restassured:$restdocsVersion"
testImplementation 'org.springframework:spring-test'
testImplementation('org.junit.vintage:junit-vintage-engine') {
exclude group: 'org.hamcrest', module: 'hamcrest-core'
}
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.0'
}
test {
outputs.dir snippetsDir
useJUnitPlatform()
}
asciidoctor {
configurations "asciidoctorExtensions"
inputs.dir snippetsDir
dependsOn test
}
jar {
dependsOn asciidoctor
from ("${asciidoctor.outputDir}/html5") {
into 'static/docs'
}
}
I placed several .adoc files under this file location:
I started the project as a Spring Boot project but when I open http://localhost:8080/docs/index.html I get white label error:
Do you know how I can serve this content as web pages?
In my Java (Gradle-based) project, I have the default test task and custom defined integrationTest task. My build.gradle looks following
plugins {
id 'de.jansauer.printcoverage' version '2.0.0'
}
apply plugin: 'idea'
apply plugin: 'java'
apply plugin: 'jacoco'
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
sourceSets {
integration {
java.srcDir "$projectDir/src/integration/java"
resources.srcDir "$projectDir/src/integration/resources"
compileClasspath += main.output + test.output
runtimeClasspath += main.output + test.output
}
}
configurations {
integrationImplementation.extendsFrom testImplementation
integrationImplementation.canBeResolved true
integrationRuntimeOnly.extendsFrom testRuntimeOnly
integrationRuntimeOnly.canBeResolved true
}
task integrationTest(type: Test) {
description = 'Runs the integration tests.'
group = 'verification'
testClassesDirs = sourceSets.integration.output.classesDirs
classpath = sourceSets.integration.runtimeClasspath
outputs.upToDateWhen { false }
useJUnitPlatform()
}
idea {
module {
testSourceDirs += sourceSets.integration.java.srcDirs
testResourceDirs += sourceSets.integration.resources.srcDirs
}
}
check.dependsOn integrationTest
repositories {
mavenCentral()
}
dependencies {
testRuntimeOnly group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: '5.8.2'
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.8.2'
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-params', version: '5.8.2'
testImplementation group: 'org.mockito', name: 'mockito-core', version: '3.4.6'
testImplementation group: 'org.mockito', name: 'mockito-junit-jupiter', version: '3.4.6'
testImplementation group: 'org.mockito', name: 'mockito-inline', version: '3.4.6'
}
test {
useJUnitPlatform()
finalizedBy jacocoTestCoverageVerification, printCoverage
}
jacocoTestReport {
reports.xml.enabled true
}
jacocoTestCoverageVerification {
violationRules {
rule {
limit {
minimum = 1.0
}
}
}
}
In general, it works fine, but there is a problem. Sometimes there are places in code that are really difficult to unit-test, and are great for integration tests. However, JaCoCo counts only coverage in unit tests. I could place finalizedBy jacocoTestCoverageVerification, printCoverage in the integrationTest task, but then I'd have two separate coverages.
My goal is to have one common coverage from both test configuration. I tried changing finalizedBy to dependsOn (with adequate logic change), but then I had no coverage at all. I don't know if it's even possible tbh, but I'm guessing it is.
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'
}
I wanted to publish an artifact to a remote repository identified by a url . Here is my build.gradle file. This is a java gradle project with some dependencies. I was able to publish this to a local .m2 repository and make use of this in another project.
plugins {
id 'java'
id 'org.springframework.boot' version '2.1.3.RELEASE'
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
id 'maven-publish'
}
group = 'com.mob.ci'
version '1.0-SNAPSHOT'
apply plugin: 'maven'
sourceCompatibility = 1.8
repositories {
maven{url 'https://proget1..../maven2/Maven/'}
}
jar {
enabled = true
}
bootJar {
enabled = false
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-couchbase'
implementation 'org.springframework.boot:spring-boot-starter-data-rest'
compile group: 'javax.validation', name: 'validation-api', version: '2.0.1.Final'
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
}
publishing {
publications {
maven(MavenPublication) {
from components.java
}
}
repositories {
maven {
url = 'https://proget1..../maven2/Maven/'
}
}
}
Here is the update the build.gradle file, that resolved the issue. Thank you #soung for the tip. I need to specify the credentials for accessing the repository.
plugins {
id 'java'
id 'org.springframework.boot' version '2.1.3.RELEASE'
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
id 'maven-publish'
}
group = 'com.mob.ci'
version '1.0-SNAPSHOT'
apply plugin: 'maven'
sourceCompatibility = 1.8
repositories {
maven{url 'https://proget1..../maven2/Maven/'}
}
jar {
enabled = true
}
bootJar {
enabled = false
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-couchbase'
implementation 'org.springframework.boot:spring-boot-starter-data-rest'
compile group: 'javax.validation', name: 'validation-api', version: '2.0.1.Final'
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
}
publishing {
publications {
maven(MavenPublication) {
from components.java
}
}
repositories {
maven {
url = 'https://proget1..../maven2/Maven/'
credentials {
username = deployRepoUsername
password = deployRepoPassword
}
}
}
}
I want to use local tomcat container which is already installed in c:\tomcat instead of cargo downloading container automatically in temp folder. Please help me here. What am i doing wrong?
Here is my build.gradle so far
group = "com.biw.hc"
version = "0.1.0_SNAPSHOT"
buildscript {
ext {
springBootVersion = "1.2.3.RELEASE"
tomcatVersion = "8.0.20"
logbackJaninoVersion = "2.7.8"
}
repositories {
jcenter()
maven { url "http://repo.spring.io/snapshot" }
maven { url "http://repo.spring.io/milestone" }
maven { url "https://plugins.gradle.org/m2/" }
}
dependencies {
classpath "org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}"
classpath "net.saliman:gradle-cobertura-plugin:2.2.7"
classpath "com.bmuschko:gradle-cargo-plugin:2.1"
}
}
apply plugin: "spring-boot"
apply plugin: "java"
apply plugin: "groovy"
apply plugin: 'war'
apply plugin: "eclipse"
apply plugin: "idea"
apply plugin: 'com.bmuschko.cargo'
apply plugin: "net.saliman.cobertura"
bootRepackage {
mainClass = 'com.biw.hc.admin.Application'
}
war {
archiveName 'hcadmin.war'
}
repositories {
mavenLocal()
jcenter()
maven { url "http://repo.spring.io/snapshot" }
maven { url "http://repo.spring.io/milestone" }
}
dependencies {
providedRuntime "org.apache.tomcat.embed:tomcat-embed-core"
providedRuntime "org.apache.tomcat.embed:tomcat-embed-el"
providedRuntime "org.apache.tomcat.embed:tomcat-embed-logging-juli"
providedRuntime "org.apache.tomcat.embed:tomcat-embed-websocket"
providedRuntime "org.apache.tomcat:tomcat-jdbc:${tomcatVersion}"
providedRuntime "org.apache.tomcat:tomcat-juli:${tomcatVersion}"
providedRuntime "org.apache.tomcat:tomcat-dbcp:${tomcatVersion}"
compile ("org.springframework.boot:spring-boot-starter-web:${springBootVersion}") {
exclude module: "spring-boot-starter-tomcat:${springBootVersion}"
}
compile "org.springframework.boot:spring-boot-starter-actuator:${springBootVersion}"
compile "org.springframework.boot:spring-boot-starter-thymeleaf:${springBootVersion}"
compile "org.springframework.boot:spring-boot-starter-data-jpa:${springBootVersion}"
compile("org.codehaus.janino:janino:${logbackJaninoVersion}")
// BIW dependencies...
compile "com.biw.hc:hc-core:0.1.0-SNAPSHOT"
// security dependencies...
compile "org.springframework.boot:spring-boot-starter-security:${springBootVersion}"
// testing dependencies...
testCompile "org.codehaus.groovy:groovy-all:2.2.0"
testCompile "org.spockframework:spock-core:0.7-groovy-2.0"
testCompile "org.spockframework:spock-spring:0.7-groovy-2.0"
testCompile "org.springframework:spring-test:2.5"
testCompile "org.springframework.boot:spring-boot-starter-test:${springBootVersion}"
compile('org.codehaus.groovy.modules.http-builder:http-builder:0.5.1')
def cargoVersion = '1.4.5'
cargo "org.codehaus.cargo:cargo-core-uberjar:$cargoVersion",
"org.codehaus.cargo:cargo-ant:$cargoVersion"
}
cargo {
containerId = 'tomcat8x'
port = 8080
deployable {
file = file('build/libs/hcadmin.war')
context = 'hcadmin'
}
local {
homeDir = file('C:\\apache-tomcat-8.0.21')
outputFile = file('build/output.log')
containerProperties {
property 'cargo.tomcat.webappsDirectory', 'build/libs'
}
}
}
I came up with a solution like this instead of using cargo plugin
build.mustRunAfter clean
task deploy(dependsOn: ['clean', 'build', 'deployWar']) << {
println '*********************'
println 'hcadmin.war installed'
println '*********************'
}
task deployWar(type: Copy) {
from war
into System.env.'TOMCAT_HOME' + "\\webapps"
}