I'm having a JavaFX project configured with Gradle in IntelliJ.
Whenever I'm trying to run gradlew.bat clean build or simply the build task directly from IntelliJ, this is what I receive:
> Task :startScripts FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':startScripts'.
> Couldn't replace placeholder in E:\git\yuber\build\scripts\yuber
I'm also using the shadowJar plugin, which actually works when I'm trying to create a jar file and run it. And it works perfectly. Although, I'm not sure why it won't build. Looked everywhere for an answer, but seems that no one actually had this problem at this moment?
This is my build.gradle file:
plugins {
id 'java'
id 'application'
id 'org.openjfx.javafxplugin' version '0.0.10'
id 'org.beryx.jlink' version '2.24.1'
id "com.github.johnrengelman.shadow" version "7.1.2"
}
group 'com.example'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
ext {
junitVersion = '5.8.2'
}
sourceCompatibility = '11'
targetCompatibility = '11'
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
application {
mainModule = 'com.example.yuber'
mainClass = 'com.example.yuber.Launcher'
}
javafx {
version = '11.0.2'
modules = ['javafx.controls', 'javafx.fxml', 'javafx.web']
}
dependencies {
implementation('org.controlsfx:controlsfx:11.1.0')
implementation('com.dlsc.formsfx:formsfx-core:11.3.2') {
exclude(group: 'org.openjfx')
}
implementation('net.synedra:validatorfx:0.1.13') {
exclude(group: 'org.openjfx')
}
implementation('org.kordamp.ikonli:ikonli-javafx:12.2.0')
implementation('org.kordamp.bootstrapfx:bootstrapfx-core:0.4.0')
implementation('eu.hansolo:tilesfx:11.48') {
exclude(group: 'org.openjfx')
}
implementation 'org.json:json:20220320'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.13.2.2'
implementation 'com.fasterxml.jackson.core:jackson-core:2.13.2'
implementation 'com.fasterxml.jackson.core:jackson-annotations:2.13.2'
implementation 'junit:junit:4.13.1'
testImplementation("org.junit.jupiter:junit-jupiter-api:${junitVersion}")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:${junitVersion}")
}
test {
useJUnitPlatform()
}
jlink {
imageZip = project.file("${buildDir}/distributions/app-${javafx.platform.classifier}.zip")
options = ['--strip-debug', '--compress', '2', '--no-header-files', '--no-man-pages']
launcher {
name = 'app'
}
}
jlinkZip {
group = 'distribution'
}
Updating the org.openjfx.javafxplugin (https://plugins.gradle.org/plugin/org.openjfx.javafxplugin) to the latest version inside build.gradle (from 0.0.10, as IntelliJ added it, to 0.0.13) seemed to have fixed the problem.
Related
I had a problem when dockerize the Gradle project.
running gradle jib
What went wrong:
Execution failed for task ':jib'.
Invalid image reference registry.hub.docker.com/myusername/${rootProject.name}, perhaps you should check that the reference is formatted correctly according to https://docs.docker.com/engine/reference/commandline/tag/#extended-description
For example, slash-separated name components cannot have uppercase letters
Root Module
setting.gradle
rootProject.name = 'myproject'
include 'discovery-service'
include 'client-service'
include 'notification-service'
include 'api-gateway'
build.gradle
jib {
var tag = 'latest'
from {
image = 'eclipse-temurin:17.0.4.1_1-jre'
}
to {
image = 'registry.hub.docker.com/myUsername/${rootProject.name}'
}
}
One of the service
plugins {
id 'java'
id 'org.springframework.boot' version '2.7.5'
id 'io.spring.dependency-management' version '1.0.15.RELEASE'
}
group = 'com.leekify'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '17'
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
jar {
baseName = 'client-service'
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
....
}
tasks.named('test') {
useJUnitPlatform()
}
setting.gradle
rootProject.name = 'client-service'
Use double-quotes instead of single quotes for the jib.to.image string so that Gradle evaluates the variable.
yesterday I created a JavaFX project and I don't know why but when I want to run the app with commands java says:
Gradle task : build
Command : java -jar "name_of_the_file.jar"
Error: Could not find or load main class com.example.HelloApplication
Caused by: java.lang.NoClassDefFoundError:javafx/application/Application
but I can run it using gradlew run
module-info.java file
module com.example{
requires javafx.controls;
requires javafx.fxml;
opens com.example ;
exports com.example;
}
Manifest.MF file
Manifest-Version: 1.0
Main-Class: com.example.HelloApplication
build.gradle file
plugins {
id 'java'
id 'application'
id 'org.openjfx.javafxplugin' version '0.0.13'
id 'org.beryx.jlink' version '2.25.0'
}
group 'com.example'
version '1.0-SNAPSHOT'
jar{
manifest{
attributes ('Main-Class' : 'com.example.HelloApplication' )
}
}
repositories {
mavenCentral()
}
ext {
junitVersion = '5.8.2'
}
sourceCompatibility = '17'
targetCompatibility = '17'
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
application {
mainModule = 'com.example'
mainClass = 'com.example.jfx.HelloApplication'
}
javafx {
version = '17.0.2'
modules = ['javafx.controls', 'javafx.fxml']
}
dependencies {
testImplementation("org.junit.jupiter:junit-jupiter-api:${junitVersion}")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:${junitVersion}")
}
test {
useJUnitPlatform()
}
jlink {
imageZip = project.file("${buildDir}/distributions/app-${javafx.platform.classifier}.zip")
options = ['--strip-debug', '--compress', '2', '--no-header-files', '--no-man-pages']
launcher {
name = 'app'
}
}
jlinkZip {
group = 'distribution'
}
and project structure
project structure
I am using inteliij idea community and my operating system is windows
I really don't know what is wrong it seems all correct to me. Strange
The Stackoverflow contains some questions regarding this issue but unfortunately, nothing works for me. For example, I read this
My build.gradle looks like this:
plugins {
id 'org.springframework.boot' version '2.3.3.RELEASE'
id 'io.spring.dependency-management' version '1.0.10.RELEASE'
id 'java'
id 'java-library'
id 'maven-publish'
id 'net.linguica.maven-settings' version '0.5'
}
tasks.withType(Test) {
testLogging {
exceptionFormat "full"
events "started", "skipped", "passed", "failed"
showStandardStreams true
}
}
sourceCompatibility = '11'
targetCompatibility = '11'
mavenSettings {
userSettingsFileName project.getProperty('settingsXml')
}
configurations.all {
resolutionStrategy {
cacheDynamicVersionsFor 0, 'seconds'
cacheChangingModulesFor 0, 'seconds'
}
}
// This configuration is necessary for publishing spring boot jar
configurations {
[apiElements, runtimeElements].each {
it.outgoing.artifacts.removeIf { it.buildDependencies.getDependencies(null).contains(jar) }
it.outgoing.artifact(bootJar)
}
}
group 'com.something.company'
version '1.0.0-SNAPSHOT'
repositories {
maven {
name 'nexus.aliter.com'
url 'https://nexus.aliter.com/repository/cloud-maven/'
}
}
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
}
}
repositories {
maven {
name 'nexus.aliter.com'
if(project.version.endsWith('-SNAPSHOT')) {
url 'https://nexus.repo.com/repository/maven-snapshots/'
} else {
url 'https://nexus.repo.com/repository/maven-releases/'
}
}
}
}
springBoot {
buildInfo()
}
test {
useJUnitPlatform()
}
dependencies {
implementation group: 'com.aliter.csp', name: 'security-lib', version: '1.0.0-SNAPSHOT'
implementation group: 'com.aliter.csp', name: 'adapter-lib', version: '1.0.0-SNAPSHOT'
}
I tried this:
configurations.all {
resolutionStrategy {
cacheDynamicVersionsFor 0, 'seconds'
cacheChangingModulesFor 0, 'seconds'
}
}
and I tried keyword changing: true, I tried gradle clean build --refresh-dependencies and nothing works for me. The gradle shows me that cannot find the snapshot dependencies.
We build the project through Jenkins, so in the matter of automation, it is necessary to not delete .gradle/cache every time. I am 100% percent sure that snapshot dependencies are available in the nexus repository.
Gradle version: 6.6.1
I found the solution, problem was that the nexus repository missed this maven-metadata.xml
I'm currently using LibericaJDK-11 as my default JRE in eclipse, also in my project. I added Gradle to my Project and everytime I Refresh the Project via Gradle. It sets the JRE to JavaSE-11. And i have to manually put it back to Liberica.
Is there a way to set a default JRE for Gradle in gradle.build oder gradle.settings?
The following code is my gradle.build.
plugins {
id 'java-library'
id 'application'
id 'pmd'
}
version = '0.0.1'
group = 'zuulsLostPlace.MainApp'
application{
mainClassName = "zuulsLostPlace.MainApp"
}
dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.4.2'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.4.2'
}
test {
useJUnitPlatform()
}
repositories {
mavenCentral()
}
task(runGameNoGUI, dependsOn: 'classes', type: JavaExec) {
group 'application'
description 'Starts the Text Adventure without GUI'
main = 'zuulsLostPlace.model.Game'
standardInput = System.in
ignoreExitValue true
classpath = sourceSets.main.runtimeClasspath
}
task(runGameGUI, dependsOn: 'classes', type: JavaExec) {
group 'application'
description 'Starts the Text Adventure with GUI'
main = 'zuulsLostPlace.MainApp'
standardInput = System.in
ignoreExitValue true
classpath = sourceSets.main.runtimeClasspath
}
task myJavadocs(type: Javadoc) {
source = sourceSets.main
tasks.withType(Javadoc) {
options.addStringOption('Xdoclint:none', '-quiet')
options.addStringOption('encoding', 'UTF-8')
options.addStringOption('charSet', 'UTF-8')
}
}
I'm am trying to publish an in-house libGDX framework to use for all the games I work on using artifactory. I have been following this guide, however, I am stuck at the point in which the project itself is actually published. My libGDX project only has a core module, as it is not a game in itself, so I did not make a desktop or android module. This is my buildscript for the whole project
buildscript {
repositories {
mavenLocal()
mavenCentral()
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
jcenter()
}
dependencies {
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:latest.release"
}
}
allprojects {
apply plugin: "eclipse"
apply plugin: "idea"
version = '1.0'
ext {
appName = "lichengine"
gdxVersion = '1.9.8'
roboVMVersion = '2.3.3'
box2DLightsVersion = '1.4'
ashleyVersion = '1.7.0'
aiVersion = '1.8.0'
}
repositories {
mavenLocal()
mavenCentral()
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
maven { url "https://oss.sonatype.org/content/repositories/releases/" }
}
}
project(":core") {
apply plugin: "java"
dependencies {
compile group: 'org.json', name: 'json', version: '20160810'
compile "com.badlogicgames.gdx:gdx:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-controllers:$gdxVersion"
}
}
tasks.eclipse.doLast {
delete ".project"
}
And here is the buildscript for the core module
apply plugin: "java"
apply plugin: 'com.jfrog.artifactory'
apply plugin: 'maven-publish'
sourceCompatibility = 1.7
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
sourceSets.main.java.srcDirs = [ "src/" ]
eclipse.project {
name = appName + "-core"
}
def libraryGroupId = 'my.com.lichengine'
def libraryArtifactId = 'lichengine'
def libraryVersion = '1.0'
publishing {
publications {
aar(MavenPublication) {
groupId libraryGroupId
version libraryVersion
artifactId libraryArtifactId
artifact("$buildDir/publications/aar/${artifactId}-release.aar")
}
}
}
artifactory {
contextUrl = 'http://mywebsite.com:8081/artifactory'
publish {
repository {
repoKey = 'libs-release-local'
username = artifactory_username
password = artifactory_password
}
defaults {
publications('aar')
publishArtifacts = true
properties = ['qa.level': 'basic', 'q.os': 'android', 'dev.team': 'core']
publishPom = true
}
}
}
When I try to run the artifactoryPublish task on the root project or the core project I get the following error:
lichengine\core\build\publications\aar\lichengine-release.aar' does not exist, and need to be published from publication aar
Am I missing something? Everything I search for online is specifically for android libraries so nothing really helps.It seems like an aar file that is supposed to be generated is not.
After a lot of pain, I figured it out. Instead of using an aar publication I am using mavenJava. Here is my updated publications block:
publications {
mavenJava(MavenPublication) {
groupId libraryGroupId
version libraryVersion
artifactId libraryArtifactId
from components.java
}
}
I also had to update the defaults block
defaults {
publications ('mavenJava')
publishArtifacts = true
properties = ['qa.level': 'basic', 'q.os': 'android', 'dev.team': 'core']
publishPom = false
}
Hopefully, anyone who sees this can use this to help them make libGDX libraries with artifactory!