I have a multimodule gradle build with a single module containing a spring boot application that consumes the artifacts of the other modules. I have the spring boot plugin applied to the single spring boot module.
Everything works correctly in Windows, but once I try the build on a Linux machine if fails. I have tried multiple linux machines (Jenkins server, Ubuntu VM, even bitbucket pipeline) and it fails with this error:
Problems reading data from Binary store in /tmp/gradle2075404181876889604.bin (exist: false)
I am not entirely sure what gradle uses this binary store for, but after debugging I found that this file name is different than binary store that every other module is using while building.
I have tried multiple gradle versions(2, 3, and 4) and several spring boot versions and they all fail with the same error. The only thing that fixes this is removing the spring boot plugin.
Here is the parent build.gradle
repositories {
mavenCentral()
}
def javaLangVersion = '1.8'
def gradleDir = "${rootProject.rootDir}/gradle"
def realProjects = allprojects - [project(':external'), project(':delivery')]
def javaProjects = realProjects - rootProject
def integrationTestProjects = javaProjects
configure(realProjects) {
group 'com.packagename'
version '1.0-SNAPSHOT'
apply plugin: 'eclipse'
apply plugin: 'idea'
}
configure(javaProjects) {
apply plugin: 'java'
targetCompatibility = javaLangVersion
sourceCompatibility = javaLangVersion
repositories {
mavenCentral()
}
dependencies {
compile group: 'org.slf4j', name: 'slf4j-api', version: "${slf4jVersion}"
compile group: 'org.slf4j', name: 'log4j-over-slf4j', version: "${slf4jVersion}"
testCompile group: 'junit', name: 'junit', version: "${junitVersion}"
testCompile group: 'org.mockito', name: 'mockito-core', version: "${mockitoVersion}"
testCompile group: 'nl.jqno.equalsverifier', name: 'equalsverifier', version: "${equalsverifierVersion}"
}
}
configure(integrationTestProjects) {
apply from: "${gradleDir}/integrationTest.gradle"
}
task wrapper(type: Wrapper) {
gradleVersion = '3.5'
}
Here is the spring boot module build.gradle file:
buildscript {
ext {
springBootVersion = '1.5.3.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootStarterVersion}")
}
}
apply plugin: 'org.springframework.boot'
apply plugin: 'war'
war {
baseName = "${project.name}"
version = "${project.version}"
}
dependencies {
compile project(':module1')
compile project(':module2')
compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-rest'
compile group: 'org.apache.httpcomponents', name: 'httpcore', version: "${httpCoreVersion}"
compile group: 'org.apache.httpcomponents', name: 'httpclient', version: "${httpClientVersion}"
compile group: 'com.h2database', name: 'h2', version: "${h2Version}"
testCompile project(':test-utils')
testCompile group: 'org.springframework.boot', name: 'spring-boot-starter-test'
}
All other modules are plain java modules and only declare a dependencies block in the build file.
I have been working on this for 2 days now so any help or suggestions would be greatly appreciated. Thanks!
Well this is super embarrasing... I had a unit test using FileUtils.getTempDirectory() and then I was cleaning that directory using FileUtils.deleteQuietly after the test and it was deleting the gradle binary store that was in the /tmp folder. The reason it wasnt showing on windows is because windows locks files.
did you verify that your gradle.properties is OK on the Linux machine ?
Related
I have a grails application written in Groovy. It is built and works when it's launched with :
./gradlew bootRun
Now I want to run it with java to put it in a Docker container. This is the Dockerfile I prepared :
FROM openjdk:8-jdk-alpine
ARG JAR_FILE=build/libs/*.war
ADD ${JAR_FILE} app.war
ENTRYPOINT ["java"]
CMD ["-Dgrails.env=development","-jar","app.war"]
The server fails to start because of the following error:
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [grails.boot.config.GrailsApplicationPostProcessor]: Factory method 'grailsApplicationPostProcessor' threw exception; nested exception is java.lang.ClassNotFoundException: com.flosslab.eGrocery.showcase.CmsTagLib
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588)
... 29 more
Caused by: java.lang.ClassNotFoundException: com.flosslab.eGrocery.showcase.CmsTagLib
When I checked the classes folder in WEB-INF, I found that the class is there in the correct path. I tried with a Tomcat setup, with Docker and without Docker and I'm still encountering the exact same error. I think something is wrong with the .WAR build. Here is the build.gradle file
build.gradle:
buildscript {
ext {
grailsVersion = project.grailsVersion
}
repositories {
mavenLocal()
maven { url "https://repo.grails.org/core" }
maven { url "https://repo.grails.org/grails/core" }
maven { url "https://plugins.gradle.org/m2/" }
}
dependencies {
classpath "org.grails:grails-gradle-plugin:$grailsVersion"
classpath "com.bertramlabs.plugins:asset-pipeline-gradle:2.5.0"
// classpath "org.grails.plugins:hibernate4:5.0.2"
classpath 'org.springframework:springloaded:1.2.8.RELEASE'
classpath "gradle.plugin.com.github.viswaramamoorthy:gradle-util-plugins:0.1.0-RELEASE"
}
}
version "1.0.49"
group "com.flosslab.egrocery"
apply plugin: "com.github.ManifestClasspath"
apply plugin: "eclipse"
apply plugin: "idea"
apply plugin: "war"
apply plugin: "org.grails.grails-web"
apply plugin: "org.grails.grails-gsp"
apply plugin: "asset-pipeline"
war.archiveName = "egrocery-showcase.war"
ext {
grailsVersion = project.grailsVersion
gradleWrapperVersion = project.gradleWrapperVersion
}
repositories {
mavenLocal()
maven { url "https://repo.grails.org/core" }
maven { url "https://repo.grails.org/grails/core" }
maven { url "http://192.168.12.16:8081/artifactory/egrocery-local" }
maven { url "http://192.168.12.16:8081/artifactory/libs-release-local" }
maven { url "http://192.168.12.16:8081/artifactory/plugins-release-local" }
mavenCentral()
}
dependencyManagement {
imports {
mavenBom "org.grails:grails-bom:$grailsVersion"
}
applyMavenExclusions false
}
def elasticsearchVersion = '5.6.8'
ext['elasticsearch.version'] = elasticsearchVersion
dependencies {
compile fileTree(dir: "libs", includes: ["*.jar"])
compile "com.flosslab.egrocery:domain:1.0.49"
compile "org.springframework.boot:spring-boot-starter-logging"
compile "org.springframework.boot:spring-boot-autoconfigure"
compile "org.springframework.boot:spring-boot-starter-actuator"
provided "org.springframework.boot:spring-boot-starter-tomcat"
compile "org.grails:grails-core"
compile "org.grails:grails-dependencies"
compile "org.grails:grails-web-boot"
compile "org.grails:grails-datastore-rest-client:5.0.3.RELEASE"
console "org.grails:grails-console"
profile "org.grails.profiles:web:$grailsVersion"
compile "org.grails.plugins:cache"
compile "org.grails.plugins:scaffolding"
compile "org.grails.plugins:hibernate4"
compile "org.grails.plugins:spring-security-rest:2.0.0.M2"
compile "org.grails.plugins:spring-security-rest-gorm:2.0.0.M2"
runtime "org.grails.plugins:asset-pipeline"
runtime group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.7'
runtime group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.7'
// compile group: 'org.elasticsearch', name: 'elasticsearch', version: elasticsearchVersion
// compile group: 'org.elasticsearch.client', name: 'transport', version: elasticsearchVersion
// compile "org.grails.plugins:elasticsearch:1.4.1"
compile group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.13'
compile "org.hibernate:hibernate-ehcache"
compile "org.grails.plugins:cache-ehcache:3.0.0.BUILD-SNAPSHOT"
compile "net.sf.ehcache:ehcache:2.10.2.2.21"
compile "net.sf.ehcache:ehcache-core:2.6.11"
compile "com.google.code.maven-play-plugin.net.tanesha.recaptcha4j:recaptcha4j:0.0.8"
runtime group: "org.postgresql", name: "postgresql", version: "42.1.4"
compile group: "net.java.dev.jna", name: "platform", version: "3.5.0"
compile group: "com.nimbusds", name: "nimbus-jose-jwt", version: "4.8"
compile group: "org.pac4j", name: "pac4j-core", version: "1.8.3"
compile "org.grails.plugins:fields"
testCompile "org.grails:grails-plugin-testing"
// testCompile "org.grails.plugins:geb"
testRuntime "org.seleniumhq.selenium:selenium-htmlunit-driver:2.47.1"
testRuntime "net.sourceforge.htmlunit:htmlunit:2.18"
}
configurations {
all {
exclude module: "bcmail-jdk14"
exclude module: "bctsp-jdk14"
exclude group: "com.google.guava", module: "guava"
exclude group: "com.google.guava", module: "guava-base"
}
}
task wrapper(type: Wrapper) {
gradleVersion = gradleWrapperVersion
}
assets {
minifyJs = true
minifyCss = true
}
gradle.properties:
grailsVersion=3.1.8
gradleWrapperVersion=2.11
Maybe there is something is lacking or something is wrong with the grails/groovy version ? I'm stuck for the entire day so I would appreciate your help.
Update :
Here is the Dockerfile I tried with Tomcat that I mentionned earlier. It gives me the exact same error.
FROM tomcat:8.5.75-jdk8-temurin
COPY egrocery-showcase.war /usr/local/tomcat/webapps
CMD ["catalina.sh", "run"]
I can't believe I wasted two days straight on this because someone wrote the package with an uppercase letter. There was a class in a package :
package com.flosslab.eGrocery.showcase
When I changed it to
package com.flosslab.egrocery.showcase
I got past this error.
What is in 2021 the best way to create an executable jar file with Gradle in IntelliJ using OpenJFX? Every solution I found is very complex and uses workarounds. This is my current build.gradle file
plugins {
id 'java'
id 'application'
id 'org.openjfx.javafxplugin' version '0.0.9'
}
tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
}
repositories {
mavenCentral()
}
javafx {
version = "15.0.1"
modules = [ 'javafx.controls', 'javafx.fxml' ]
}
mainClassName = 'com.company.crawl.main.Main'
group 'com.company'
version '1.0-SNAPSHOT'
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
compile group: 'com.google.code.gson', name: 'gson', version: '2.8.6'
compile group: 'com.microsoft.sqlserver', name: 'mssql-jdbc', version: '9.2.0.jre15'
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.11'
compile group: 'org.apache.commons', name: 'commons-csv', version: '1.8'
}
jar {
from configurations.compile.collect {zipTree it}
manifest.attributes "Main-Class": "com.company.crawl.main.Main"
}
If I run gradle :jar, the jar file includes the dependencies but not the openjfx sdk. What do I have to do to run the jar using the openjfx sdk?
UPDATE 1
changed the jar path to this:
jar {
manifest {
attributes 'Main-Class': 'com.company.crawl.main.Main'
}
from {
configurations.runtimeClasspath.collect {it.isDirectory() ? it : zipTree(it)}
}
}
after rebuilding the jar, I get the error: "JavaFX runtime components are missing". I don't know why because in the jar file the javafx folders are included. After that I added the VM options:
--module-path /path/to/javafx-sdk/lib --add-modules=javafx.controls,javafx.fxml
and the jar file runs. So what am I doing wrong?
I am trying to build a java project using gradle6.6 and open jre 11.0.2, in eclipse 03-2020.
I am facing compilation issue, while building my project which uses the classes from jrt-fs.jar; e.g.'sun.net.www.protocol.http.Handler', which is in open jre 11.
public class Manager extends sun.net.www.protocol.https.Handler{
(package sun.net.www.protocol.https is declared in module java.base, which
does not export it)
1 error
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileJava'.
> Compilation failed; see the compiler error output for details.
Following is my build.gradle:
apply plugin: 'java'
apply plugin: 'application'
allprojects {
apply plugin: 'java'
sourceCompatibility = '11.0.2'
targetCompatibility = JavaVersion.VERSION_11
}
repositories {
mavenCentral()
}
dependencies {
compile fileTree(dir: 'lib', include: '*.jar')
compile group: 'org.hamcrest', name: 'hamcrest-all', version: '1.3'
compile group: 'junit', name: 'junit', version: '4.10'
compile group: 'jmock', name: 'jmock', version: '1.0.1'
compile group: 'com.google.code.findbugs',name: 'findbugs', version: '1.3.9'
compile group: 'cglib', name: 'cglib', version: '2.1'
testCompile group: 'junit', name: 'junit', version: '4.10'
}
also, how can I avoid building the test classes, through gradle?
As #dave_thompson_085 suggested, Issue is due to modular restriction (JDK-1.9 onwards) on sun.net.* packages , as they are internal to JDK. The above packages are accessible in JDK -1.8. We need to fix our code
If you are using gradle, add this compilerArgs in build.gradle
options.encoding = "UTF-8"
options.incremental = true
options.compilerArgs.addAll([
"--add-exports",
"java.base/sun.net.www.protocol.http=ALL-UNNAMED"
])
}
I'm trying to configure gradle to use lombok to compile my project but I don't want the classes appearing in my jar. On the other side I need the mysql-connector dependency packages in the jar, but it's not needed for compiling. This is my build.gradle file:
group 'de.albritter'
version '1.0-SNAPSHOT'
apply plugin: 'java'
jar {
manifest {
attributes 'Main-Class': 'de.albritter.main.Main'
}
from {
configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
}
}
sourceCompatibility = 1.7
repositories {
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.11'
compile group: 'org.projectlombok', name: 'lombok', version: '1.16.8'
compile group: 'mysql', name: 'mysql-connector-java', version: '5.1.39'
}
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath group: 'mysql', name: 'mysql-connector-java', version: '5.1.39'
classpath group: 'org.projectlombok', name: 'lombok', version: '1.16.8'
}
}
I've seen some solutions using compileOnly but if i try to use it I just gete an error that this method is not known.
My gradle version is 2.9
How do I tell gradle that I don't need lombok in my jar?
What you're asking for is variously known as compileOnly or in the maven world, provided dependency. The compileOnly configuration was introduced in gradle in version 2.12. I would strongly recommend moving to the latest version of gradle (2.14 at the time of writing this).
If you need to stick to the older version, there are some workarounds you can find by looking for "gradle provided dependency". One way to do this is to declare your own configuration, lets call it provided and adding its dependencies to compile time classpath. So in your build.gradle:
configurations{
provided
}
sourceSets {
main.compileClasspath += configurations.provided
test.compileClasspath += configurations.provided
test.runtimeClasspath += configurations.provided
}
dependencies {
...
provided 'group:module:version'
...
}
Or alternatively you can use the prodeps plugin which does most of this work for you.
I'm totally new to gradle so it may be a obvious problem:
I'm using eclipse with gradle and I actually have no problem adding dependencies for junit or stuff, it adds the junit lib to the gradle dependencies and there's no problem using junit, but if i try to use args4j (also with adding the dependency) it just doesn't work.
Just to make sure there's no problem with the build.gradle
apply plugin: 'java'
apply plugin: 'eclipse'
sourceCompatibility = 1.8
version = '1.0'
jar {
manifest {
attributes 'Implementation-Title': 'title',
'Implementation-Version': version,
'Main-Class':'path.to.main.Main'
}
}
repositories {
mavenCentral()
}
test {
systemProperties 'property': 'value'
}
dependencies{
compile 'args4j:args4j-site:2.0.25'
testCompile group: 'junit', name: 'junit', version: '4.+'
}
and No I'm not using title or path.to.main ^^
Eclipse shows me that the import (args4j) cannot be resolved
You forgot main "args4j" module:
compile group: 'args4j', name: 'args4j', version: '2.0.25'
compile group: 'args4j', name: 'args4j-site', version: '2.0.25'
With gradle-7.1 this works for me:
// build.gradle
repositories {
mavenCentral()
}
dependencies {
implementation group: 'args4j', name: 'args4j', version: '2.33'
implementation group: 'args4j', name: 'args4j-site', version: '2.33'
}