could not find ant-javafx in gradle app - java

While writing my first app using JavaFX, I ensured that JAVA_HOME is setup properly, and included the javafx-gradle-plugin into my app, but got an error of missing ant-javafx-library which actually available in my JDK :(
my build.gradle and the error msg I got are below:
// set up the kotlin-gradle plugin
buildscript {
ext.kotlin_version = '1.1.60'
repositories {
mavenLocal() // mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "de.dynamicfiles.projects.gradle.plugins:javafx-gradle-plugin:8.8.2"
}
}
// apply the kotlin-gradle plugin
apply plugin: "kotlin"
apply plugin: 'javafx-gradle-plugin'
// add kotlin-stdlib dependencies.
repositories {
mavenLocal() // mavenCentral()
}
dependencies {
//dependencies from a remote repositor
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
compile "no.tornado:tornadofx:1.7.12"
compile "de.dynamicfiles.projects.gradle.plugins:javafx-gradle-plugin:8.8.2"
}
jar {
manifest {
//Define mainClassName as: '[your_namespace].[your_arctifact]Kt'
attributes ('Main-Class': 'MyAppKt', "Implementation-Title": "Gradle",
"Implementation-Version": 1)
}
// NEW LINE HERE !!!
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
}
sourceSets {
main.kotlin.srcDirs += 'src/kotlin'
main.resources.srcDirs += 'src/resources'
}
kotlin {
experimental.coroutines 'enable'
}
compileKotlin {
kotlinOptions.jvmTarget= 1.8 // optional, Minimum jvmTarget of 1.8 needed since Kotlin 1.1
kotlinOptions.suppressWarnings = true
}

I was able to solve it, by downloading the javafx.plugin from here.
Then created a 'plugin' folder, and copied that file in it.
Last, I installed this plugging into my gradle.build as:
apply from: "plugins/javafx.plugin"
So, my last gradle.build is:
// set up the kotlin-gradle plugin
buildscript {
ext.kotlin_version = '1.1.60'
repositories {
mavenLocal() // mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// classpath files('plugins/javafx.plugin')
}
}
// apply the kotlin-gradle plugin
apply plugin: "kotlin"
apply from: "plugins/javafx.plugin" // apply from: "http://dl.bintray.com/content/shemnon/javafx-gradle/8.1.1/javafx.plugin"
// add kotlin-stdlib dependencies.
repositories {
mavenLocal() // mavenCentral()
}
dependencies {
//dependencies from a remote repositor
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
compile "no.tornado:tornadofx:1.7.12"
}
jar {
manifest {
//Define mainClassName as: '[your_namespace].[your_arctifact]Kt'
attributes ('Main-Class': 'MainKt', "Implementation-Title": "Gradle",
"Implementation-Version": 1)
}
// NEW LINE HERE !!!
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
}
sourceSets {
main.kotlin.srcDirs += 'src/kotlin'
main.resources.srcDirs += 'src/resources'
}
kotlin {
experimental.coroutines 'enable'
}
compileKotlin {
kotlinOptions.jvmTarget= 1.8 // optional, Minimum jvmTarget of 1.8 needed since Kotlin 1.1
kotlinOptions.suppressWarnings = true
}
and my app structure, is:
UPDATE
OPTION 2
Install the new plugin here by:
buildscript {
repositories {
mavenCentral() // or mavenLocal()
}
dependencies {
compile "de.dynamicfiles.projects.gradle.plugins:javafx-gradle-plugin:8.8.2"
}
}
If interested in using mavenLocal() then is can be downloaded using the below command:
mvn dependency:get -DrepoUrl=https://mvnrepository.com/artifact/de.dynamicfiles.projects.gradle.plugins/javafx-gradle-plugin/8.8.2 -Dartifact=de.dynamicfiles.projects.gradle.plugins:javafx-gradle-plugin:8.8.2
To get the mvn command line, you get download it from here, add it to your path then call it from anywhere.

Related

Could not find or load main class gradle 7.0 spring-boot 2.5.6

I just made an update from spring boot version "2.2.1.RELEASE" to 2.5.6 and along with that I also updated the gradle version to 7.0. Before the update everything worked fine but after the update it seems that the bootRun task doesn't find the main class.
This is the error received:
Deprecated Gradle features were used in this build, making it
incompatible with Gradle 8.0. Use '--warning-mode all' to show the
individual deprecation warnings. See
https://docs.gradle.org/7.0/userguide/command_line_interface.html#sec:command_line_warnings
12 actionable tasks: 12 executed
Error: Could not find or load main class com.test.TestApplication
FAILURE: Build failed with an exception.
I ve followed the documentation https://docs.spring.io/spring-boot/docs/current/gradle-plugin/reference/htmlsingle/#running-your-application and I have the following build.gradle
buildscript {
ext {
springBootVersion = '2.5.6'
}
repositories {
// ..
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath "org.springframework.boot:spring-boot-starter-jersey:${springBootVersion}"
classpath("net.ltgt.gradle:gradle-apt-plugin:0.15")
classpath 'gradle.plugin.com.palantir.gradle.gitversion:gradle-git-version:0.11.0'
}
}
apply plugin: "java"
apply plugin: "war"
apply plugin: 'eclipse'
apply plugin: "idea"
apply plugin: "org.sonarqube"
apply plugin: "jacoco"
apply plugin: "maven-publish"
apply plugin: "net.ltgt.apt"
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'com.palantir.git-version'
def mapStructVersion = "1.3.0.Final"
def swaggerVersion = "1.6.3"
def junitVersion = "4.13.2"
sourceCompatibility = 1.8
sourceSets {
main {
java {
srcDir "${buildDir.absolutePath}/generated/source/apt/main"
}
}
test {
java {
srcDir "${buildDir.absolutePath}/generated/source/apt/main"
}
}
}
configurations.all {
resolutionStrategy.cacheChangingModulesFor 0, "seconds"
}
repositories {
// ...
}
task preBuild {
delete "${buildDir.absolutePath}/generated/source/apt/main"
}
build.dependsOn preBuild
configurations {
developmentOnly.extendsFrom compile
runtimeClasspath {
extendsFrom developmentOnly
}
}
/**
* Fix extension/file too long issue under windows
*/
task pathingJar(type: Jar) {
dependsOn configurations.developmentOnly
archiveAppendix = 'pathing'
doFirst {
manifest {
attributes "Class-Path": configurations.developmentOnly.files.collect {
it.toURI().toString().replaceFirst(/file:\/+/, '/')
}.join(' ')
}
}
}
/**
* With gradle 7, a duplicate strategy must be set in order to not encountering error during copy operation.
* Solution: EXCLUDE strategy do not allow duplicates by ignoring subsequent items to be created at the same path.
*/
processIntegrationTestResources {
duplicatesStrategy(DuplicatesStrategy.EXCLUDE)
}
bootRun {
main = 'com.test.TestApplication'
dependsOn pathingJar
doFirst {
classpath = files(sourceSets.main.output.files, pathingJar.archiveFile)
}
def debugPort = project.properties["${project.name}.debugPort"]
if (debugPort) {
jvmArgs = ["-Xdebug", "-Xnoagent", "-Djava.compiler=NONE", "-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=${debugPort}"]
}
if (System.getProperty("LOG_PATH") == null) {
System.setProperty("LOG_PATH", project.projectDir.getCanonicalPath() + "/log")
}
if (System.getProperty("spring.profiles.active") == null) {
System.setProperty("spring.profiles.active", "some-profile")
}
if (System.getProperty("servicelayer.rrLogHumanReadable") == null) {
System.setProperty("servicelayer.rrLogHumanReadable", "true")
}
systemProperties = System.properties
}
def compileDependencies = [
"org.springframework.cloud:spring-cloud-starter-bootstrap:3.0.4",
"org.springframework.boot:spring-boot-starter-web",
"org.springframework.boot:spring-boot-starter-jersey",
"org.springframework.boot:spring-boot-starter-security",
"org.springframework.boot:spring-boot-starter-actuator",
"org.springframework.boot:spring-boot-starter-data-jpa",
"org.springframework.boot:spring-boot-starter-cache",
"io.swagger:swagger-jersey2-jaxrs:${swaggerVersion}",
"io.jsonwebtoken:jjwt:0.9.0",
"org.bitbucket.b_c:jose4j:0.6.3",
'org.flywaydb:flyway-core',
"org.mapstruct:mapstruct-jdk8:${mapStructVersion}",
"com.github.ben-manes.caffeine:caffeine",
'org.bouncycastle:bcprov-jdk15on:1.60'
]
// defined some dependencies. Not relevant
dependencies {
implementation compileDependencies
providedRuntime providedRuntimeDependencies
testImplementation testCompileDependencies
}
I tried both ways, from command line and from ide (IntelliJ)
clean bootRun -Dspring.profiles.active="some-profile"
I found the solution and the issue has been inside the task pathingJar.
Before:
task pathingJar(type: Jar) {
dependsOn configurations.developmentOnly
archiveAppendix = 'pathing'
doFirst {
manifest {
attributes "Class-Path": configurations.developmentOnly.files.collect {
it.toURI().toString().replaceFirst(/file:\/+/, '/')
}.join(' ')
}
}
}
After:
task pathingJar(type: Jar) {
dependsOn configurations.runtimeClasspath
archiveAppendix = 'pathing'
doFirst {
manifest {
attributes "Class-Path": configurations.runtimeClasspath.files.collect {
it.toURI().toString().replaceFirst(/file:\/+/, '/')
}.join(' ')
}
}
}
So the solution has been to change the following two lines of code
dependsOn configurations.developmentOnly -> dependsOn configurations.runtimeClasspath
attributes "Class-Path": configurations.developmentOnly.files.collect {...} -> attributes "Class-Path": configurations.runtimeClasspath.files.collect {...}
Long story short is that somehow another tasks interfered with this task on developmentOnly scope and I had to change it to runtimeClasspah
Edit:
Another issue might be inside of bootRun task. You can define the package where is the main class.
bootRun {
main = 'edu.somepacke.MyMainClass'
dependsOn pathingJar
doFirst {
classpath = files(sourceSets.main.output.files, pathingJar.archiveFile)
}
//extra logic
}

Adding dependency causes main class to not be found

When adding the com.spotify:docker-client:3.5.12 dependency to build.gradle, it causes my main class "com.gamedash.daemon.Main" to not be found. I have absolutely no clue what this might be causing. Removing the dependency resolves the issue.
build.gradle
group 'com.gamedash.daemon'
version '0.1'
apply plugin: 'java'
apply plugin: 'application'
apply plugin: 'eclipse'
apply plugin: 'idea'
sourceCompatibility = 9
targetCompatibility = 9
repositories {
mavenCentral()
maven {
url 'https://jetbrains.bintray.com/pty4j'
}
}
application {
mainClassName = 'com.gamedash.daemon.Main'
}
jar {
manifest {
attributes(
'Main-Class': 'com.gamedash.daemon.Main'
)
}
from {
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
}
sourceSets {
main {
resources {
srcDirs "src/main/resources", "src/main/configs"
}
}
}
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'net.sf.proguard:proguard-gradle:6.2.2'
}
}
dependencies {
implementation('me.tongfei:progressbar:0.7.4')
implementation('com.google.guava:guava:28.2-jre')
implementation('com.corundumstudio.socketio:netty-socketio:1.7.17')
implementation('org.jetbrains.pty4j:pty4j:0.8.6')
implementation('commons-io:commons-io:2.6')
implementation('org.zeroturnaround:zt-zip:1.13')
implementation('org.apache.httpcomponents:httpclient:4.5.8')
implementation('com.beust:jcommander:1.78')
implementation('com.google.code.gson:gson:2.8.5')
implementation('com.github.oshi:oshi-core:4.4.2')
implementation('net.java.dev.jna:jna:5.3.1')
implementation('net.java.dev.jna:jna-platform:5.3.1')
implementation('org.apache.commons:commons-lang3:3.9')
implementation('com.sparkjava:spark-core:2.9.1')
implementation('org.slf4j:slf4j-api:1.7.6')
implementation('org.slf4j:slf4j-log4j12:1.7.5')
implementation('org.apache.mina:mina-core:2.0.0-M2')
implementation('org.apache.ftpserver:ftplet-api:1.1.1')
implementation('org.apache.ftpserver:ftpserver-core:1.1.1')
implementation('org.apache.sshd:sshd-core:2.4.0')
implementation('org.apache.sshd:sshd-sftp:2.4.0')
compile('com.spotify:docker-client:3.5.12:shaded')
implementation('org.beryx:text-io:3.3.0')
implementation('com.fasterxml.jackson.core:jackson-core:2.9.8')
implementation('com.fasterxml.jackson.core:jackson-annotations:2.9.8')
implementation('com.fasterxml.jackson.core:jackson-databind:2.9.8')
compile group: 'javax.xml.bind', name: 'jaxb-api', version: '2.2.4'
implementation group: 'commons-validator', name: 'commons-validator', version: '1.4.0'
implementation files('lib/icmp4j-all.jar')
implementation files('lib/Schokker-IT-Rest-Client.jar')
implementation files('lib/com.gamedash.daemon.common.jar')
}
task obfuscate(type: proguard.gradle.ProGuardTask) {
configuration 'proguard.txt'
injars "build/libs/gamedash-daemon-${ version }.jar"
outjars "build/libs/gamedash-daemon-${ version }-obfuscated.jar"
}
Turns out that the library in question uses Bouncycastle and thus requires a signed jar to run. Would have been much more pleasant if the error message would have said so, instead of telling me that the class was not found.
Fixed it by adding the following rule to my build.gradle
exclude 'META-INF/*.RSA', 'META-INF/*.SF','META-INF/*.DSA'

Test package does not read Kotlin classes defined in main package

I cannot seem to access main classes within the test package in my Kotlin module within an Android Studio project. Please note that all code shown below is within a Kotlin JVM module that is imported into the Android app.
Here's my src/main/java code:
import com.google.gson.annotations.SerializedName
data class Customer(val password1: String,
val password2: String,
#SerializedName("last_name") val lastName: String,
#SerializedName("first_name") val firstName: String,
val email: String)
My test code in src/test/java:
class CreateUser {
#Test
fun createRandomUser() {
val random = Random()
val randomNumber = random.nextInt(10000000)
val customer = Customer("password", "password", "lastName", "firstName", "ted$randomNumber#gmail.com")
}
}
My build.gradle code looks like the following:
buildscript {
ext.kotlin_version = '1.1.4-3'
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath 'me.tatarka:gradle-retrolambda:3.7.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'me.tatarka.retrolambda'
apply plugin: 'kotlin'
repositories {
mavenCentral()
jcenter()
}
dependencies {
// some other compile dependencies
compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
testCompile "org.hamcrest:hamcrest-all:1.3"
testCompile 'junit:junit:4.11'
testCompile 'org.mockito:mockito-all:1.9.5'
testCompile "org.jetbrains.kotlin:kotlin-test"
testCompile "org.jetbrains.kotlin:kotlin-test-junit"
}
task javadocJar(type: Jar) {
classifier = 'javadoc'
from javadoc
}
task sourcesJar(type: Jar) {
classifier = 'sources'
from sourceSets.main.allSource
}
artifacts {
archives sourcesJar
archives javadocJar
}
compileKotlin {
kotlinOptions {
jvmTarget = "1.6"
}
}
compileTestKotlin {
kotlinOptions {
jvmTarget = "1.6"
}
}
The root build.gradle file looks as follows:
// Top-level build file where you can add configuration options
common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
maven {
url "https://jitpack.io"
credentials { username authToken }
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
ext {
versionName = "0.1.1"
rxJavaVersion = "2.1.3"
okHttpVersion = "3.9.0"
retrofitVersion = "2.3.0"
rxJava2AdapterVersion = "1.0.0"
googleGsonVersion = "2.8.0"
}
The error I get is that gradle cannot resolve Customer (Unresolved reference: Customer) in the Test class. It doesn't seem to include main classes into the test source directory. Yet, it resolves in the IDE.
Ok, I have found the solution. It seems I have to specify the src folders explicitly in my build.gradle and put all Kotlin code in src/main/kotlin and src/test/kotlin respectively.
sourceSets {
main.kotlin.srcDirs = ['src/main/kotlin', 'src/main/java']
main.java.srcDirs = []
test.kotlin.srcDirs = ['src/test/kotlin', 'src/test/java']
test.java.srcDirs = ['src/test/kotlin', 'src/test/java']
}
Once I did that, the tests started to work as expected - reports are even generated on Jenkins which is great.

How to package dependencies in a Grails 3 plugin using gradle?

I'm having difficulty generating a Grails 3.2.7 plugin with its dependencies.
This works and creates a JAR with all dependencies:
gradle clean build
..but not this; the JAR has no dependencies, just plugin project files:
gradle publishToMavenLocal
My gradle file, I know there's something missing, and based on the docs it's my understand there's no native feature to do this.
buildscript {
ext {
grailsVersion = project.grailsVersion
}
repositories {
mavenLocal()
maven { url "https://repo.grails.org/grails/core" }
jcenter()
}
dependencies {
classpath "org.grails:grails-gradle-plugin:$grailsVersion"
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:3.0.1"
}
}
plugins {
id "io.spring.dependency-management" version "0.5.2.RELEASE"
id "com.jfrog.bintray" version "1.2"
}
version "3.1-SNAPSHOT"
group "mygroup"
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: "org.springframework.boot"
apply plugin: "com.jfrog.artifactory"
apply plugin: "org.grails.grails-plugin"
apply plugin: "org.grails.grails-gsp"
apply plugin: 'maven-publish'
ext {
grailsVersion = project.grailsVersion
gradleWrapperVersion = project.gradleWrapperVersion
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
idea {
module {
downloadSources = true
}
}
repositories {
mavenLocal()
mavenCentral()
maven { url "https://repo.grails.org/grails/core" }
}
dependencyManagement {
imports {
mavenBom "org.grails:grails-bom:$grailsVersion"
}
applyMavenExclusions false
}
dependencies {
provided 'org.springframework.boot:spring-boot-starter-logging'
provided "org.springframework.boot:spring-boot-starter-actuator"
provided "org.springframework.boot:spring-boot-autoconfigure"
provided "org.springframework.boot:spring-boot-starter-tomcat"
provided "org.grails:grails-web-boot"
provided "org.grails:grails-dependencies"
provided 'javax.servlet:javax.servlet-api:3.1.0'
compile "org.grails:grails-plugin-testing"
testCompile "com.fiftyonred:mock-jedis:0.4.0"
console "org.grails:grails-console"
compile "redis.clients:jedis:2.5.2"
}
task wrapper(type: Wrapper) {
gradleVersion = gradleWrapperVersion
}
artifactory {
contextUrl = 'http://myrepo/'
}
task sourceJar(type: Jar) {
from sourceSets.main.allJava
}
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
}
}
}
The issue stems from the publishing section:
When I change this to:
task jarWithPlainPom(type: Jar) {
from sourceSets.main.output
from configurations.runtime
}
publishing {
publications {
mavenJava(MavenPublication) {
artifact jarWithPlainPom
}
}
}
It includes most of the needed dependencies, however the POM is not updated and the project fails when importing the plugin.

No signature of method: archives.internal.DefaultManifest.srcFile()

I am trying to setUp my first gradle project with android studio:
I am getting the following error, which does not make any sense to me since 'app/src/main/AndroidManifest.xml' is a string.
Error:(23, 0) No signature of method:
org.gradle.api.java.archives.internal.DefaultManifest.srcFile() is
applicable for argument types: (java.lang.String) values:
[app/src/main/AndroidManifest.xml]
The gradle build script looks like this:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.9.2'
classpath 'org.robolectric.gradle:gradle-android-test-plugin:0.9.4'
classpath "org.mockito:mockito-core:1.9.5"
}
}
apply plugin: 'android'
allprojects {
repositories {
mavenCentral()
}
}
sourceSets {
main {
manifest.srcFile("app/src/main/AndroidManifest.xml")
}
unitTest {
java.srcDir file('src/test/java')
resources.srcDir file('src/test/res')
}
}
configurations {
unitTestCompile.extendsFrom runtime
unitTestRuntime.extendsFrom unitTestCompile
}
dependencies {
repositories {
mavenCentral()
}
unitTestCompile files("$project.buildDir/classes/release")
unitTestCompile 'junit:junit:4.10'
unitTestCompile 'org.robolectric:robolectric:2.1.+'
unitTestCompile 'com.google.android:android:4.0.1.2'
}
task unitTest(type:Test, dependsOn: assemble) {
testClassesDir = project.sourceSets.unitTest.output.classesDir
classpath = project.sourceSets.unitTest.runtimeClasspath
}
android {
compileSdkVersion 19
buildToolsVersion "19.0.0"
}
check.dependsOn unitTest
Thanks for any help.
Torsten
The error message means that either there is no method named srcFile on sourceSets.main.manifest, or it doesn't accept a string as argument. (Often it's the former.) I think that what you are trying to configure here is android { sourceSets { ... } }, not sourceSets { ... }.

Categories