I'm running into dependency issues trying to run an unfamilliar gradle build that I believe worked on an older version of gradle - gradle

I've been put into the unfortunate situation where I need to deploy a gradle build on a time crunch when I have never worked with it before. I believe this worked previously but on an older version of gradle that I am unable to roll back to.
I'm running Gradle 7.1 and am receiving this error message:
Could not find method compile() for arguments [{group=org.slf4j,
name=slf4j-api, version=1.7.21}] on object of type
org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
This is the build.gradle file
allprojects {
ext.springVersion="4.2.0.RELEASE"
ext.slf4jVersion="1.7.10"
ext.springDataVersion = "1.8.0.RELEASE"
ext.hibernateVersion = "4.3.9.Final"
ext.springSecurityVersion = "4.2.0.RELEASE"
ext.springDataMongoDBVersion = "1.7.0.RELEASE"
ext.mysqlConnectorVersion = "5.1.13"
}
subprojects {
apply plugin: 'java'
apply plugin : 'eclipse-wtp'
sourceCompatibility = 1.8
targetCompatibility = 1.8
group = 'com.aet.accel'
version = '1.0.0'
repositories {
mavenLocal()
mavenCentral()
maven{url "http://jaspersoft.artifactoryonline.com/jaspersoft/third-party-ce-artifacts/"}
maven{url "https://jaspersoft.jfrog.io/jaspersoft/third-party-ce-artifacts/"}
}
dependencies {
// logging
compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.21'
compile group: 'org.apache.logging.log4j', name: 'log4j-slf4j-impl', version: '2.5'
compile "org.apache.logging.log4j:log4j-core:2.5"
compile "org.apache.logging.log4j:log4j-api:2.5"
}
}
Any sort of assistance is very much appreciated, as I am very out of my depth on this one. Thank you for taking a look.

compile has been deprecated, so for libraries use api or implementation

Related

Upgrading from gradle 5.2 -> 6.0 gives error: could not find or load main class

I'm upgrading gradle for my Grails application from version 5.2 to 6.0 following their official guide: https://docs.gradle.org/current/userguide/upgrading_version_5.html
This is not going that well, as I can now not start any of my subprojects. The one I'm testing is called integration, and after the upgrade (and changing compile to implementation), the build.gradle looked like this:
buildscript {
repositories {
mavenLocal()
maven { url "https://repo.grails.org/grails/core" }
maven artifactory
}
dependencies {
classpath "org.jsonschema2pojo:jsonschema2pojo-gradle-plugin:$jsonToPojoVersion"
classpath "org.grails:grails-gradle-plugin:$grailsVersion"
classpath "org.grails.plugins:views-gradle:$grailsViewsGradleVersion"
classpath "com.bertramlabs.plugins:asset-pipeline-gradle:$assetPipelineVersion"
classpath "org.codehaus.groovy:groovy-all:$groovyVersion"
}
}
apply plugin: "war"
apply plugin: "org.grails.grails-web"
apply plugin: "org.grails.plugins.views-json"
apply from: "${rootProject.rootDir}/gradle/common.gradle"
apply from: "${rootProject.rootDir}/gradle/deployable.gradle"
apply from: "${rootProject.rootDir}/gradle/json2pojo.gradle"
springBoot {
mainClassName = 'dk.erst.plandata.integration.Application'
}
dependencies {
profile "org.grails.profiles:rest-api"
implementation group: 'org.hibernate', name: 'hibernate-validator', version: hibernateValidatorVersion
implementation "org.grails.plugins:cache-ehcache:$ehcacheVersion"
implementation group: 'com.googlecode.json-simple', name: 'json-simple', version: googleJsonSimpleVersion
implementation group: 'com.itextpdf', name: 'itextpdf', version: "$itextpdfVersion"
implementation "org.xhtmlrenderer:core-renderer:$xhtmlRenderVersion"
implementation "com.jcraft:jsch:$jcraftVersion"
implementation "org.grails.plugins:rendering:$grailsRenderingVersion"
implementation "org.grails.plugins:views-json"
implementation "org.grails.plugins:views-json-templates"
implementation "net.sf.json-lib:json-lib:$netsfJsonVersion"
implementation "person-og-organisation:pogo-grails-plugin:$pogoGrailsPlugin"
implementation "person-og-organisation:pogo-common:$pogoCommonsVersion"
implementation "beskedfordeler:beskedfordeler-plugin:$beskedfordelerPlugin"
implementation group: 'dokumentlager', name: 'dokumentlager-grails4-plugin', version: "$dokumentlagerPlugin"
implementation "erkerne:text-manager-plugin:$textmanagerPlugin"
implementation "erkerne:text-manager-api:$textmanagerApiVersion"
implementation "sag:sagslager-grails-plugin:$sagslagerGrailsPlugin"
implementation "sag:sag-enums:$sagEnumVersion"
implementation "sag:sagslager-api:$sagslagerApiVersion"
implementation "sag:sagslager-interface:$sagslagerInterfaceVersion"
implementation "sag:sagsindeks-grails-plugin:$sagsindeksPluginVersion"
implementation "sag:sagsindeks-object-marshallers:$sagsindeksPluginVersion"
implementation "sag:sagsindeks-api:$sagsindeksApiVersion"
implementation project(":model")
implementation project(":utils")
implementation project(":validering")
}
assets {
minifyJs = false
minifyCss = false
maxThreads = 1
}
However, I can no longer run my application, and now get this error:
> Task :integration:bootRun FAILED
Error: Could not find or load main class dk.erst.plandata.integration.Application
This was not a problem in gradle 5.2. I have tried to apply the "application" plugin, changing springBoot {} to application {} but it made no difference. I have also tried to remove mainClassName altogether, but same result.
I can see that other grails projects in my unit use gradle 6.0, but don't even specify mainClassName and it seems to work.
As was already noted in the comments, it’s hard to say what’s going wrong with this little information and especially without knowing what the applied Gradle scripts contain. So here’s just a guess: I’ve sometimes seen weird errors when upgrading the Gradle version because of outdated build/ and/or .gradle/ directories. Deleting those directories after an upgrade often does wonders.

Getting SpringBoot error - Execution failed for task ':compileJava

The below is my build.gradle.
When I Bootrun, i get the error
Execution failed for task ':compileJava
invalid source release: 18
plugins {
id 'org.springframework.boot' version '2.6.9'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
}
group = 'com.loginapp'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '18'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-web'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
tasks.named('test') {
useJUnitPlatform()
}
Since you're using IntelliJ, shared the screenshot and told us you alread checked the java version and I already got this error a few times here is my TODO I go through when I get this error:
Do what you showed us on the screenshot (Check Project Version and language level)
Do the same for Modules (Project Structure > Modules) Don't forget the Dependencies Tab there you can find the module SDK
Check Java Compiler (Settings > Build, Execution, Deployment > Compiler > Java Compiler) there you can see a Project bytecode version & Per-module bytecode version -> Check those
Hope this works :)

How to get dependency version form parent project in Gradle

I have a Gradle project and I want to create a submodule but I am getting an FAILURE when building the project.
The error message is
Execution failed for task ':child-project:compileJava'
> Could not resolve all files for configuration 'child-project:compileClasspath'.
> Could not find org.springframework.boot:spring-boot-starter:.
Required by:
project :parent-project
This is the parent project build.gradle file:
plugins {
id 'org.springframework.boot' version '2.3.0.RELEASE'
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
id 'java'
}
allprojects {
apply plugin: 'java'
group = 'com.test'
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
repositories {
//local nexus
}
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter'
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.boot:spring-boot-starter-web'
//other dependencies
}
This is the child project build.gradle:
plugins {
id 'java'
}
group = 'com.test'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = JavaVersion.VERSION_11
dependencies {
compile 'org.springframework.boot:spring-boot-starter'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
}
Please help, thanks in advance.
In order to be able to specify Spring Boot dependencies without versions, you need to apply the Spring Boot plugin to all modules. Right now you only have it in the parent project, but not the child.
Because applying the plugin will also, by default, disable the normal jar task can create a bootJar instead, you need to change this for libraries:
// Child build file
plugins {
// Note that there are no versions on the plugins in the child project as this is defined by the ones in the parent
id 'org.springframework.boot'
id 'io.spring.dependency-management'
}
bootJar {
enabled = false
}
jar {
enabled = true
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter'
}
Alternatively, you could also scrap the io.spring.dependency-management plugin (and the org.springframework.boot plugin in the child project), and instead import the Spring Boot BOM as a platform:
// Child build file (alternative)
dependencies {
// Use 'platform' for making the versions in the BOM a recommendation only, and 'enforcedPlatform' for making them a requirement.
// Note that you need the version of the BOM, so I recommend putting it in a property.
implementation enforcedPlatform("org.springframework.boot:spring-boot-dependencies:2.3.0.RELEASE")
// Here you can leave out the version
implementation 'org.springframework.boot:spring-boot-starter'
}
I usually go for the latter alternative as this allows me to use normal Gradle semantics. But it is mostly just preference.
(And just a small note to your build script: the compile configuration is deprecated. It is used in the line compile 'org.springframework.boot:spring-boot-starter'. You probably just copy/pasted it from somewhere, but you should replace it with implementation.)

How to Package a JavaFX Application as a standalone executable EXE using Gradle

I recently downloaded the JavaFX 12 SDK and started a Gradle Application in IntelliJ IDE.I have also imported all the necessary dependencies in the build.gradle file. Now I want to package the final JavaFX application as a standalone executable exe file that can be clicked and run on Windows. How can I do this since I started the project as a Gradle Project. The Build Artifact Menu Item on IntelliJ seems to be permanently disabled.
Here is a setup of my build.gradle file
plugins {
id 'java'
id 'application'
id 'org.openjfx.javafxplugin' version '0.0.7'
}
javafx {
version = "12.0.1"
modules = ['javafx.base', 'javafx.controls', 'javafx.web']
}
group 'condo'
version '1'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
mainClassName = 'rumbler.launcher.ApplicationLoader'
dependencies {
testImplementation group: 'junit', name: 'junit', version: '4.12'
implementation group: 'org.iq80.leveldb', name: 'leveldb', version: '0.12'
implementation 'org.controlsfx:controlsfx:11.0.0'
implementation 'com.google.code.gson:gson:2.8.5'
implementation group: 'org.json', name: 'json', version: '20180813'
}
Thanks alot.

Unable to pass argument from gradle command line to Spring project (not Boot)

I am developing Spring project.
I would like to load credentials from the command line not storying them in the code. I'm trying to execute this gradle command
gradlew build -Dspring.datasource.username=tester
and when I startup the Spring project, the program stops on a breakpoint and I see whether variable is declared or not. I have tried using -P instead of -D but it still didn't help.
I deploy the spring app remotely using bmuschko plugin I've tried to use, but also without success. I checked in java code Properties by using System.getProperties() and Environment object supported by Spring.
gradlew cargoredeployremote -Dspring.datasource.username=tester
Application properties are loaded succesfully.
IMPORTANT: I saw many tutorials how to make it but using Spring Boot I use just selected components from Spring.
For instance: http://nixmash.com/post/passing-arguments-to-spring-boot - this doesn't work in my case because I have no bootRun task.
Any ideas? Am I missing something in my steps?
Here is my build.gradle
group 'example'
version '1.0.0'
apply plugin: 'application'
apply plugin: 'war'
apply plugin: 'java'
apply plugin: 'com.bmuschko.cargo'
apply plugin: 'org.liquibase.gradle'
compileJava.options.encoding = 'UTF-8'
mainClassName = 'api.optic.config.WebAppInitializer'
sourceCompatibility = 1.8
buildscript {
repositories{
jcenter()
mavenCentral()
}
dependencies{
classpath 'com.bmuschko:gradle-cargo-plugin:2.2.3'
classpath 'org.junit.platform:junit-platform-gradle-plugin:1.0.0-RC3'
classpath 'org.liquibase:liquibase-core:3.4.1'
classpath "org.liquibase:liquibase-gradle-plugin:1.2.4"
classpath "mysql:mysql-connector-java:5.1.13"
}
}
project.ext {
springVersion = "4.3.6.RELEASE"
junitVersion = "5.0.0-RC3"
}
repositories {
mavenCentral()
}
dependencies {
compile "org.springframework:spring-core:${springVersion}"
compile "org.springframework:spring-context:${springVersion}"
compile "org.springframework:spring-context-support:${springVersion}"
compile "org.springframework:spring-beans:${springVersion}"
compile "org.springframework:spring-web:${springVersion}"
compile "org.springframework:spring-webmvc:${springVersion}"
compile "org.springframework:spring-orm:${springVersion}"
compile "org.springframework:spring-oxm:${springVersion}"
compile "org.springframework:spring-jdbc:${springVersion}"
compile "org.springframework:spring-test:${springVersion}"
compile group: 'mysql', name: 'mysql-connector-java', version: '5.1.38'
compile group: 'javax.mail', name: 'javax.mail-api', version: '1.5.6'
compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.25'
compile group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.2'
compile group: 'com.fasterxml.jackson.module', name: 'jackson-module-parameter-names', version: '2.9.0.pr2'
compile group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-jdk8', version: '2.9.0.pr2'
compile group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-jsr310', version: '2.9.0.pr2'
compile 'javax.servlet:javax.servlet-api:3.1.0'
testCompile "org.junit.jupiter:junit-jupiter-api:${junitVersion}"
testRuntime("org.junit.jupiter:junit-jupiter-engine:${junitVersion}")
}
cargo {
containerId = 'tomcat8x'
port = 8080
deployable {
context = 'example'
}
remote {
hostname = 'host.name.com'
username = 'tomcat'
password = 'pass'
}
Basically were 2 issues
1. Name mismatch: in application.properties the name inside the ${} was different than this provided from command-line
Solution:
application.properties
spring.datasource.username=${username}
and in gradle command-line
gradle build -Pusername=tester
2. Dot issue with gradle:
Can't put
gradle build -Pspring.datasource.username=tester
even if you have in application.properties
spring.datasource.username=${spring.datasource.username}
because you get an exception:
Execution failed for task ':processResources'.
Could not copy file '.\src\main\resources\application.properties' to '.\build\resources\main\application.properties'.
Solution:
Instead of dots use _ sign
gradle build -Pspring_datasource_username=tester
and in Application properties
spring.datasource.username=${spring_datasource_username}

Resources