SpringBoot gradle plugin complains "Unresolved reference: providedRuntime" - spring-boot

I'm following the latest SpringBoot gradle plugin reference in order to setup a SpringBoot project that can build a uberjar.
Below is the full content of build.gradle.kts:
plugins {
java
application
id("org.springframework.boot") version "2.2.1.RELEASE"
id("io.spring.dependency-management") version "1.0.8.RELEASE"
}
repositories {
jcenter()
}
dependencies {
implementation("org.springframework.boot:spring-boot-starter-web")
providedRuntime("org.springframework.boot:spring-boot-starter-tomcat")
testImplementation("org.testng:testng:6.14.3")
}
application {
// Define the main class for the application.
mainClassName = "com.demo.App"
}
val test by tasks.getting(Test::class) {
// Use TestNG for unit tests
useTestNG()
}
dependencyManagement {
imports {
mavenBom(org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES)
}
}
Unfortunately, when I run gradle commands I get the following error:
> Configure project :
e: /Users/xux/Documents/toys/web/build.gradle.kts:15:5: Unresolved reference: providedRuntime
FAILURE: Build failed with an exception.
* Where:
Build file '/Users/xux/Documents/toys/web/build.gradle.kts' line: 15
* What went wrong:
Script compilation error:
Line 15: providedRuntime("org.springframework.boot:spring-boot-starter-tomcat")
^ Unresolved reference: providedRuntime
1 error
I'm using Java 1.8.0_201, Gradle 6.0, Kotlin 1.3.50, Mac OS X 10.15.1 x86_64.

Related

Grails 5.2.0 create-app, throws "Cannot resolve dependency org.springframework.boot:spring-boot-dependencies:2.7.0 no repositories are defined"

I am starting a new grails application, I am using grails 5.2.0 (Latest as of today)
I generated a skeleton using :
~/grails-5.2.0/bin/grails create-app data_portal --profile=react
However, trying to run the application always gives me following error :
Configure project :server
Cannot resolve reloading agent JAR: Failed to resolve imported Maven boms: Cannot resolve external dependency org.springframework.boot:spring-boot-dependencies:2.7.0 because no repositories are defined.
Required by:
project :server
FAILURE: Build completed with 2 failures.
1: Task failed with an exception.
Where:
Build file '.../server/build.gradle' line: 20
What went wrong:
A problem occurred evaluating project ':server'.
Receiver class grails.util.Environment does not define or inherit an implementation of the resolved method 'abstract java.lang.Object getProperty(java.lang.String)' of interface groovy.lang.GroovyObject.
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.
==============================================================================
2: Task failed with an exception.
What went wrong:
A problem occurred configuring project ':server'.
Failed to notify project evaluation listener.
Receiver class grails.util.Environment does not define or inherit an implementation of the resolved method 'abstract java.lang.Object getProperty(java.lang.String)' of interface groovy.lang.GroovyObject.
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.
==============================================================================
Get more help at https://help.gradle.org
Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.9/userguide/command_line_interface.html#sec:command_line_warnings
CONFIGURE FAILED in 233ms
This is how my settings.gradle looks like
include 'client', 'server'
This is how my server/build.gradle looks like
buildscript {
repositories {
maven { url "https://repo.grails.org/grails/core" }
maven { url "https://plugins.gradle.org/m2/" }
}
dependencies {
classpath "org.grails:grails-gradle-plugin:$grailsGradlePluginVersion"
classpath "com.github.node-gradle:gradle-node-plugin:1.3.0"
classpath "org.grails.plugins:hibernate5:7.3.0"
classpath "org.grails.plugins:views-gradle:2.3.2"
}
}
version "0.1"
group "dp"
apply plugin:"eclipse"
apply plugin:"idea"
apply plugin:"war"
apply plugin:"org.grails.grails-web"
apply plugin:"com.github.node-gradle.node"
apply plugin:"org.grails.plugins.views-json"
repositories {
maven { url "https://repo.grails.org/grails/core" }
}
dependencyManagement {
imports {
mavenBom('org.springframework.boot:spring-boot-dependencies:2.7.0')
}
applyMavenExclusions false
}
configurations {
developmentOnly
runtimeClasspath {
extendsFrom developmentOnly
}
}
dependencies {
developmentOnly("org.springframework.boot:spring-boot-devtools")
compileOnly "io.micronaut:micronaut-inject-groovy"
console "org.grails:grails-console"
implementation "org.springframework.boot:spring-boot-starter-logging"
implementation "org.springframework.boot:spring-boot-starter-validation"
implementation "org.springframework.boot:spring-boot-autoconfigure"
implementation "org.grails:grails-core"
implementation "org.springframework.boot:spring-boot-starter-actuator"
implementation "org.springframework.boot:spring-boot-starter-tomcat"
implementation "org.grails:grails-plugin-url-mappings"
implementation "org.grails:grails-plugin-rest"
implementation "org.grails:grails-plugin-codecs"
implementation "org.grails:grails-plugin-interceptors"
implementation "org.grails:grails-plugin-services"
implementation "org.grails:grails-plugin-datasource"
implementation "org.grails:grails-plugin-databinding"
implementation "org.grails:grails-web-boot"
implementation "org.grails:grails-logging"
implementation "org.grails.plugins:cache"
implementation "org.grails.plugins:async"
implementation "org.grails.plugins:hibernate5"
implementation "org.hibernate:hibernate-core:5.6.9.Final"
implementation "org.grails.plugins:views-json"
implementation "org.grails.plugins:views-json-templates"
profile "org.grails.profiles:react"
runtimeOnly "org.glassfish.web:el-impl:2.2.1-b05"
runtimeOnly "com.h2database:h2"
runtimeOnly "org.apache.tomcat:tomcat-jdbc"
runtimeOnly "javax.xml.bind:jaxb-api:2.3.1"
testImplementation "io.micronaut:micronaut-inject-groovy"
testImplementation "org.grails:grails-gorm-testing-support"
testImplementation "org.mockito:mockito-core"
testImplementation "io.micronaut:micronaut-http-client"
testImplementation "org.grails:grails-web-testing-support"
testImplementation "org.grails:views-json-testing-support"
testImplementation "org.hibernate.validator:hibernate-validator:6.1.7.Final"
}
bootRun {
ignoreExitValue true
jvmArgs(
'-Dspring.output.ansi.enabled=always',
'-noverify',
'-XX:TieredStopAtLevel=1',
'-Xmx1024m')
sourceResources sourceSets.main
String springProfilesActive = 'spring.profiles.active'
systemProperty springProfilesActive, System.getProperty(springProfilesActive)
}
tasks.withType(GroovyCompile) {
configure(groovyOptions) {
forkOptions.jvmArgs = ['-Xmx1024m']
}
}
tasks.withType(Test) {
useJUnitPlatform()
}
This is how my client/build.gradle looks like:
plugins {
id "com.github.node-gradle.node" version "1.3.0"
}
node {
version = '10.15.0' // https://nodejs.org/en/
yarnVersion = '1.13.0' // https://yarnpkg.com/en/
download = true
}
task bootRun(dependsOn: 'start') {
group = 'application'
description = 'Run the client app (for use with gradle bootRun -parallel'
}
task start(type: YarnTask, dependsOn: 'yarn') {
group = 'application'
description = 'Run the client app'
args = ['run', 'start']
}
task build(type: YarnTask, dependsOn: 'yarn') {
group = 'build'
description = 'Build the client bundle'
args = ['run', 'build']
}
task test(type: YarnTask, dependsOn: 'yarn') {
group = 'verification'
description = 'Run the client tests'
args = ['run', 'test']
}
task eject(type: YarnTask, dependsOn: 'yarn') {
group = 'other'
description = 'Eject from the create-react-app scripts'
args = ['run', 'eject']
}
This seem to be resolving after changing grailsGradlePluginVersion from grailsGradlePluginVersion=5.2 to grailsGradlePluginVersion=5.1.x. in gradle.properties
It looks from the deprecation warning like you were building using Gradle 6.9.
Grails 5 requires Gradle 7.
I encountered the same issue by accidentally using the gradle command instead of gradlew.
gradlew uses the version of Gradle from the project's Gradle Wrapper, but the gradle command will run whatever Gradle version is on your PATH -- in my case 6.9.2 -- so I got the same exception.
For others in the same situation:
If your project has a wrapper, run ./gradlew build from the project's ROOT
If your project has no wrapper, you can add one by running gradle wrapper --gradle-version 7.2 from the project's ROOT
If you don't want to use a wrapper, install Gradle 7.x, set your GRADLE_HOME environment variable to the new install location (instead of your v6 or earlier install) and gradle build should work fine.

JavaFX module does not export to unnamed module

I am building a JavaFX application using gradle (with Kotlin and TornadoFX). Building and running it works fine with the below gradle build and IntelliJ but using the application plugin, and running the application, I get the following error:
Caused by: java.lang.IllegalAccessError: superinterface check failed: class de.codecentric.centerdevice.javafxsvg.SvgImageLoaderFactory (in
unnamed module #0x591c2277) cannot access class com.sun.javafx.iio.ImageLoaderFactory (in module javafx.graphics) because module javafx.gr
aphics does not export com.sun.javafx.iio to unnamed module #0x591c2277
Below is my gradle build script. How can I solve this.
plugins {
id 'org.jetbrains.kotlin.jvm' version '1.3.50'
id 'application'
id 'org.openjfx.javafxplugin' version '0.0.8'
}
application {
mainClassName = 'MainKt'
}
javafx {
version = "13"
modules = ['javafx.controls', 'javafx.base', 'javafx.graphics']
}
repositories {
mavenCentral()
mavenLocal()
jcenter()
maven {
url "https://plugins.gradle.org/m2/"
}
maven {
url "http://4thline.org/m2"
}
}
dependencies {
...
}
tasks.test {
useJUnitPlatform()
testLogging {
events("passed", "skipped", "failed")
}
}
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}
Since I was working with a non-module project and was relying on JavaFX's modules, that is what caused the errors when I executed
> gradle run
I appended the following to my gradle file:
run {
applicationDefaultJvmArgs = ['--add-exports=javafx.graphics/com.sun.javafx.iio=ALL-UNNAMED',
'--add-exports=javafx.graphics/com.sun.javafx.iio.common=ALL-UNNAMED',
'--add-exports=javafx.graphics/com.sun.javafx.scene=ALL-UNNAMED',
'--add-exports=javafx.graphics/com.sun.glass.ui=ALL-UNNAMED',
]
jvmArgs = ['--add-exports=javafx.graphics/com.sun.javafx.iio=ALL-UNNAMED',
'--add-exports=javafx.graphics/com.sun.javafx.iio.common=ALL-UNNAMED',
'--add-exports=javafx.graphics/com.sun.javafx.scene=ALL-UNNAMED',
'--add-exports=javafx.graphics/com.sun.glass.ui=ALL-UNNAMED',
]
}
The reason the "applicationDefaultJvmArgs" is there is due to the fact that the application gradle plugin uses that to configure jvm arguments instead of "jvmArgs".

Gradle plugin that loads org.springframework.boot into projects

I'm writing a custom gradle plugin Foo and I want to load the org.springframework.boot plugin
into projects that apply the Foo plugin. I can load various other plugins this way, but this
particular plugin doesn't want to behave the same way.
Foo build.gradle
buildscript {
ext {
springBootVersion = "2.1.3.RELEASE"
}
}
apply plugin: "groovy"
repositories {
maven { url "http://custom.repo/blah" }
}
dependencies {
implementation gradleApi()
implementation localGroovy()
implementation("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
Foo plugin
class BuildPlugin implements Plugin<Project> {
#Override
void apply(Project project) {
project.repositories {
maven { url "http://custom.repo/blah" }
}
project.plugins.apply("org.springframework.boot")
}
}
Project build.gradle
buildscript {
dependencies {
classpath files("/some/cool/path/foo-plugin.jar")
}
}
apply plugin: "com.whatever.foo-id"
Project build output
$ ./gradlew --stacktrace clean build
FAILURE: Build failed with an exception.
* Where:
Build file '/cool/project/location/bar/build.gradle' line: 40
* What went wrong:
A problem occurred evaluating root project 'bar'.
> Failed to apply plugin [id 'com.whatever.foo-id']
> Plugin with id 'org.springframework.boot' not found.
Is it possible to apply a plugin 1 from plugin 2 where plugin 1 is a classpath dependency?
This isn't possible. The classpath is what pulls in the plugins, so it is impossible for them to modify the thing before they are pulled in.

Plugin with id 'com.github.spotbugs' not found

I'm configuring SpotBugs plugin for a Gradle project for the first time.
buildscript {
repositories {
maven {
url 'https://plugins.gradle.org/m2/'
}
}
dependencies {
classpath 'gradle.plugin.com.github.spotbugs:spotbugs-gradle-plugin:1.6.6'
}
}
apply plugin: 'com.github.spotbugs'
When running gradle check I'm getting error Plugin with id 'com.github.spotbugs' not found. What am I doing wrong?
Gradle version 5.0.

How to avoid "cannot load Java class oracle.jdbc.OracleDriver" in a JRuby Gradle project?

When trying to include the Oracle JDBC driver (ojdbc7.jar) in my JRuby Gradle project, I always get a "cannot load Java class oracle.jdbc.OracleDriver" at runtime. Here's my basic build.gradle:
buildscript {
repositories { jcenter() }
dependencies {
classpath 'com.github.jengelman.gradle.plugins:shadow:[1.2.2,2.0)'
classpath 'com.github.jruby-gradle:jruby-gradle-plugin:%%VERSION%%'
classpath 'com.github.jruby-gradle:jruby-gradle-jar-plugin:1.3.3'
}
}
apply plugin: "com.github.jruby-gradle.jar"
repositories { jcenter() }
dependencies {
jrubyJar "rubygems:colorize:0.7.7+"
jrubyJar 'org.slf4j:slf4j-simple:1.7.12'
}
jrubyJar {
initScript "${projectDir}/entrypoint.rb"
}
And here's my entrypoint.rb:
require 'java'
java_import 'java.sql.DriverManager'
java_import 'oracle.jdbc.OracleDriver'
puts "Hello world"
Output of build + run steps:
frank$ ./gradlew jrubyJar
:prepareJRubyJar UP-TO-DATE
:jrubyJar UP-TO-DATE
BUILD SUCCESSFUL
Total time: 2.027 secs
frank$ java -jar build/libs/plsql-unit-tester-jruby.jar
NameError: cannot load Java class oracle.jdbc.OracleDriver
...
Following the advice in How to use oracle jdbc driver in gradle project, I tried adding this to my build.gradle:
dependencies {
compile files('lib/ojdbc7.jar')
}
But this causes an error at compile time:
Could not find method compile() for arguments [file collection] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
I then tried to add it as a runtime dependency as suggested in How to add OJDBC6.jar in build.gradle file?:
dependencies {
runtime files('lib/odjbc7.jar')
}
But this again raises a compile error:
Could not find method runtime() for arguments [file collection] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
So I'm stuck - how can I correctly add odjbc7.jar (or any external jar) as a dependency in my JRuby Gradle project?
A workaround for the problem is to install the Oracle JDBC driver into the local Maven repository and add the mavenLocal() as repository and the driver jar as an additional dependency.
The driver can be installed like so:
mvn install:install-file -Dfile=ojdbc7.jar -DgroupId=com.oracle -DartifactId=ojdbc7 -Dversion=12.1.0.2 -Dpackaging=jar
The final build.gradle looks like this:
buildscript {
repositories { jcenter() }
dependencies {
classpath 'com.github.jruby-gradle:jruby-gradle-plugin:1.3.3'
classpath 'com.github.jruby-gradle:jruby-gradle-jar-plugin:1.3.3'
}
}
apply plugin: "com.github.jruby-gradle.jar"
repositories {
mavenLocal()
jcenter()
}
dependencies {
jrubyJar "rubygems:colorize:0.7.7+"
jrubyJar 'org.slf4j:slf4j-simple:1.7.12'
jrubyJar 'com.oracle:ojdbc7:12.1.0.2'
}
jrubyJar {
initScript "${projectDir}/entrypoint.rb"
}

Resources