I have application.properties with that code:
spring.config.additional-location=file:///C:/Users/user/Desktop/project/cfg.properties
spring.datasource.driver-class-name=oracle.jdbc.OracleDriver
spring.jpa.database-platform=org.hibernate.dialect.Oracle10gDialect
spring.jpa.hibernate.ddl-auto=validate
spring.jpa.show-sql=true
and in cfg.properties it looks like that:
spring.datasource.url=jdbc:oracle:thin:#correctDbUrl
spring.datasource.username=user
spring.datasource.password=pass
I think there is something wrong with the path - can't it be outside the project or what happened? This is an error (url is correct, it works when placed directly in application.properties):
Description:
Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.
Reason: Failed to determine suitable jdbc url
Gradle:
buildscript {
ext {
springBootVersion = '2.0.3.RELEASE'
}
repositories {
maven { url "someRepository" }
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 = 'com.abc'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
maven { url "someRepository" }
mavenCentral()
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-web')
compileOnly('org.projectlombok:lombok')
testCompile('org.springframework.boot:spring-boot-starter-test')
compile(group: 'com.hynnet', name: 'oracle-driver-ojdbc6', version: '12.1.0.1')
compile("org.springframework.boot:spring-boot-starter-data-jpa")
}
Set the following environment variable.
SET SPRING_CONFIG_LOCATION=classpath:/application.properties,file:C:/Users/user/Desktop/project/cfg.properties
you can remove "spring.config.additional-location" from the property file.
Related
When trying to run my program using gradle bootRun, the error shows that
Failed to apply plugin 'org.springframework.boot'
Configuration with name 'runtime' not found
The following is my build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.5.3.RELEASE")
}
}
apply plugin: 'war'
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'application'
jar {
baseName = 'blockchain-demo'
version = '0.0.1'
}
war {
baseName = 'blockchain-demo'
version = '0.0.1'
}
application {
mainClass = 'web.Application'
}
repositories {
mavenCentral()
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencies {
compile("org.springframework.boot:spring-boot-starter-thymeleaf")
compile("org.springframework.boot:spring-boot-devtools")
testCompile("org.springframework.boot:spring-boot-starter-test")
testCompile("junit:junit")
}
I assume you're using Gradle 7. In Gradle 7, the configurations compile, testCompile, runtime and testRuntime have been removed in favor of implementation, testImplementation, runtimeOnly and testRuntimeOnly. That's why Gradle issues
Failed to apply plugin 'org.springframework.boot' Configuration with name 'runtime' not found
To fix the issue, you should use the Gradle version that is supported by the Spring Boot Gradle Plugin version you're using (1.5.3, according to the snippet provided). The system requirements lists Gradle version 2 and 3 as requirement for Spring Boot 1.5.3. Everything thereafter is not supported.
Spring Boot 2.5.0 supports Gradle 6.8, 6.9, or 7.x
See here for a good reference on Gradle 7 configurations: https://docs.spring.io/spring-boot/docs/2.5.0/gradle-plugin/reference/htmlsingle/
This will get you off the ground:
plugins {
id 'org.springframework.boot' version '2.5.0'
}
apply plugin: 'java'
apply plugin: 'io.spring.dependency-management'
dependencies {
implementation('org.springframework.boot:spring-boot-starter-web')
implementation('org.springframework.boot:spring-boot-starter-data-jpa')
}
repositories {
mavenCentral()
}
I created my skeleton project from http://start.spring.io . But when I build the application, Gradle cannot resolve the HATEOAS dependency. Here is the error I get:
Error:java: Illegal char <:> at index 78:
C:\Users\TempUser\Downloads\hateoas\Could not resolve
org.springframework.boot:spring-boot-starter-hateoas:2.0.4.RELEASE.
This is my build.gradle file:
buildscript {
ext {
springBootVersion = '2.0.4.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 = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('org.springframework.boot:spring-boot-starter-hateoas:2.0.4.RELEASE')
compile('org.springframework.boot:spring-boot-starter-web')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
This declaration
compile('org.springframework.boot:spring-boot-starter-hateoas:2.0.4.RELEASE')
cause error. Change to
compile('org.springframework.boot:spring-boot-starter-hateoas')
This is what under the hood
You've already specified the spring boot components' version right here:
ext {
springBootVersion = '2.0.4.RELEASE'
}
Hence, all starter dependencies must be specified without the version value. Use:
compile('org.springframework.boot:spring-boot-starter-hateoas')
instead of
compile('org.springframework.boot:spring-boot-starter-hateoas:2.0.4.RELEASE')
Hope this helps
I have a spring boot project (1.5.3 release) and using gradle 4.4.
I'll build a .jar executable for install a service on linux server.
but I'm having problems generating the executable .jar file.
buildscript {
ext {
springBootVersion = '1.5.8.RELEASE'
//springBootVersion = '2.0.3.RELEASE'
}
repositories {
mavenCentral()
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'application'
springBoot {
executable = true
}
group = 'com.mygroup'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('org.springframework.boot:spring-boot-starter-security')
compile('org.springframework.boot:spring-boot-starter-thymeleaf')
compile("org.springframework.boot:spring-boot-starter-web")
compile('org.thymeleaf.extras:thymeleaf-extras-springsecurity4')
compile group: 'com.amazonaws', name: 'aws-java-sdk', version: '1.11.371'
compile group: 'com.amazonaws', name: 'aws-java-sdk-s3', version: '1.11.370'
runtime('org.springframework.boot:spring-boot-devtools')
runtime('mysql:mysql-connector-java')
testCompile('org.springframework.boot:spring-boot-starter-test')
testCompile('org.springframework.security:spring-security-test')
testCompile('com.jayway.jsonpath:json-path')
}
How i can generate the .jar?
There missing dependency for boot jar.
add this in build.gradle:
bootJar {
baseName = 'application-name'
version = '1.0.0'
}
command in terminal:
gradle bootjar
you can try this:
plugins {
id 'java'
id "maven-publish"
}
publishing {
publications {
maven(MavenPublication) {
groupId = 'com.your.project'
version = '0.0.1-SNAPSHOT'
from components.java
}
}
}
repositories {
mavenCentral()
}
and run command
gradle publishToMavenLocal
jar file will be generated in local maven repository.
I have a Gradle project in IntelliJ which I am using to control my dependencies but I am new to Gradle so I am probably doing something wrong.
I am getting this error when running my code:
java.sql.SQLException: No suitable driver found for jdbc:mariadb://<db address>
the build.gradle file:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.5.10.RELEASE")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
jar {
baseName = 'gs-rest-service'
version = '0.1.0'
}
repositories {
mavenCentral()
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencies {
compile("org.springframework.boot:spring-boot-starter-web")
testCompile('org.springframework.boot:spring-boot-starter-test')
}
version '1.0-SNAPSHOT'
apply plugin: 'java'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
}
dependencies {
// https://mvnrepository.com/artifact/org.mariadb.jdbc/mariadb-java-client
compile group: 'org.mariadb.jdbc', name: 'mariadb-java-client', version: '1.1.7'
}
The jdbc.properties file that I am also using:
jdbc.drivers=com.mariadb.jdbc.Driver
jdbc.url=jdbc:mariadb://<db address>
jdbc.user=root
jdbc.password=password
What am I doing wrong?
You are missing a dependency on the MariaDB Java driver hence this message:
java.sql.SQLException: No suitable driver found for jdbc:mariadb://<db address>
You can add the MariaDB Java driver to your classpath by updating the dependencies block of build.gradle ...
dependencies {
compile("org.springframework.boot:spring-boot-starter-web")
compile("org.mariadb.jdbc:mariadb-java-client")
testCompile('org.springframework.boot:spring-boot-starter-test')
}
Testing fails.
How fix exception?
Here is stacktrace and code:
Could not determine the dependencies of task ':test'.
Configuration with name 'default' not found.
My parent settings.gradle
rootProject.name = 'opti'
include 'web'
build.gradle
allprojects {
repositories {
mavenCentral()
}
group 'com.opti'
version '1.0'
apply plugin: 'java'
apply plugin: 'groovy'
dependencies {
testCompile 'org.codehaus.groovy:groovy-all:2.3.11',
'org.spockframework:spock-maven:0.7-groovy-2.0'
}
}
Tested module settings.gradle
rootProject.name = 'web'
include 'web'
build.gradle
group 'com.opti'
version '1.0'
apply plugin: 'groovy'
apply plugin: 'java'
repositories {
mavenCentral()
}
dependencies {
compile(project(':web'))
}
#Artur check that first:
https://docs.gradle.org/current/userguide/java_plugin.html
It seems that gradle could not find default configuration for web project.
You could also check if running this command helps
gradle :opti:test
or
gradle :web:test