I am trying to configure a project using h2, jooq and flyway. However, once the nu.studer.jooq plugin generates the config.xml it's unable to find the org.h2.driver I have the depedency in my build.gradle which is shown below along with the error I keep getting.
plugins {
id 'java'
id 'application'
id 'org.springframework.boot' version '2.2.4.RELEASE'
id 'nu.studer.jooq' version '4.0'
id 'org.flywaydb.flyway' version '6.2.3'
}
ext['jooq.version'] = '3.12.3'
sourceCompatibility = 11.0
repositories {
mavenCentral()
jcenter()
}
dependencies {
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: '2.2.4.RELEASE'
implementation group: 'org.jooq', name: 'jooq', version: '3.12.3'
implementation group: 'com.h2database', name: 'h2', version: '1.4.199'
}
application {
mainClassName = 'exampleapp.App'
}
jooq {
version = '3.12.3'
edition = 'OSS'
sample(sourceSets.main) {
jdbc {
driver = 'org.h2.Driver'
url = 'jdbc:h2:~/test'
user = 'sa'
password = ''
schema = 'public'
}
generator {
name = 'org.jooq.util.DefaultGenerator'
strategy {
name = 'org.jooq.util.DefaultGeneratorStrategy'
}
database {
name = 'org.jooq.meta.h2.H2Database'
}
generate {
relations = true
deprecated = false
records = true
immutablePojos = true
fluentSetters = true
}
target {
packageName = 'generated.jooq'
directory = '$projectDir/src/generated/jooq'
}
}
}
}
flyway {
url = 'jdbc:h2:~/test'
user = 'sa'
password = ''
schemas = ['public']
}
generateSampleJooqSchemaSource.dependsOn flywayMigrate
The error I receive when I run gradle clean build is as follows:
java.lang.ClassNotFoundException: org.h2.Driver
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
at org.jooq.codegen.GenerationTool.loadClass0(GenerationTool.java:925)
at org.jooq.codegen.GenerationTool.loadClass(GenerationTool.java:869)
at org.jooq.codegen.GenerationTool.run0(GenerationTool.java:334)
at org.jooq.codegen.GenerationTool.run(GenerationTool.java:221)
at org.jooq.codegen.GenerationTool.generate(GenerationTool.java:216)
at org.jooq.codegen.GenerationTool.main(GenerationTool.java:188)
Not sure why it can't find h2 in the classpath, any ideas?
Figured it out, I needed to add
jooqRuntime {
dependecies: 'com.h2database:h2:1.4.199'
}
To allow the task to find org.h2.Driver in the classpath
Related
I have a Java library https://github.com/skycavemc/skycavelib which I want to use in a Kotlin project. This is the build.gradle where I have the library as dependency:
import java.util.Properties
import java.io.FileInputStream
plugins {
kotlin("jvm") version "1.7.10"
}
group = "de.skycave"
version = "1.0.0"
val localProperties = Properties()
localProperties.load(FileInputStream(rootProject.file("local.properties")))
repositories {
mavenCentral()
maven { url = uri("https://repo.papermc.io/repository/maven-public/") }
maven { url = uri("https://jitpack.io") }
maven {
url = uri("https://maven.pkg.github.com/skycavemc/skycavelib")
credentials {
username = localProperties.getProperty("gpr.user")
password = localProperties.getProperty("gpr.key")
}
}
}
dependencies {
implementation(kotlin("stdlib"))
compileOnly("io.papermc.paper:paper-api:1.19.2-R0.1-SNAPSHOT")
implementation("de.skycave:skycavelib:1.0.2")
}
java {
toolchain.languageVersion.set(JavaLanguageVersion.of(17))
}
I also made sure I have a file named local.properties in my project where I set gpr.user and gpr.key correctly. The authentication works and the library is downloaded and indexed. IntelliJ also shows the library under "External Libraries".
When I try to use a class from that library, IntelliJ's autocompletion suggests the correct import. But after importing it, IntelliJ says "Unresolved reference" in the line of the import and the line where I use that class.
However, the gradle build still succeeds. Also, I only experience this issue when I import something from that library in a Kotlin class. In a Java class, IntelliJ can resolve the reference. This problem does not only happen in one specific project, but in all projects where I try to import something from that library, which means it's probably not an issue with the project configuration. The other Java library I use (paper-api) works fine when importing in both Kotlin and Java files. Invalidating caches and reloading all gradle projects has not solved the issue.
I suppose there is something misconfigured in my library https://github.com/skycavemc/skycavelib. Does someone have an idea what could have went wrong there? This is my build.gradle for the library I am trying to import from:
plugins {
id 'java'
id 'org.jetbrains.kotlin.jvm' version '1.7.10'
id 'com.github.johnrengelman.shadow' version '7.1.2'
id 'maven-publish'
}
group = 'de.skycave'
version = '1.0.2'
def localProperties = new Properties()
localProperties.load(new FileInputStream(rootProject.file("local.properties")))
repositories {
mavenCentral()
maven {
name = 'papermc-repo'
url = 'https://repo.papermc.io/repository/maven-public/'
}
maven {
name = 'sonatype'
url = 'https://oss.sonatype.org/content/groups/public/'
}
maven {
name = 'jitpack'
url = 'https://jitpack.io'
}
}
dependencies {
implementation 'org.jetbrains.kotlin:kotlin-stdlib:1.7.10'
compileOnly 'io.papermc.paper:paper-api:1.19.2-R0.1-SNAPSHOT'
implementation 'org.mongodb:mongodb-driver-sync:4.7.1'
implementation 'com.google.code.gson:gson:2.9.1'
implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.12.0'
implementation group: 'commons-io', name: 'commons-io', version: '2.11.0'
implementation 'com.github.heuerleon:mcguiapi:v1.3.5'
}
def targetJavaVersion = 17
java {
def javaVersion = JavaVersion.toVersion(targetJavaVersion)
sourceCompatibility = javaVersion
targetCompatibility = javaVersion
if (JavaVersion.current() < javaVersion) {
toolchain.languageVersion = JavaLanguageVersion.of(targetJavaVersion)
}
manifest {
attributes 'Main-Class': "de.skycave.skycavelib.SkyCaveLib"
}
}
tasks.withType(JavaCompile).configureEach {
if (targetJavaVersion >= 10 || JavaVersion.current().isJava10Compatible()) {
//noinspection GroovyAssignabilityCheck, GroovyAccessibility
options.release = targetJavaVersion
}
}
processResources {
def props = [version: version]
inputs.properties props
filteringCharset 'UTF-8'
filesMatching('plugin.yml') {
expand props
}
}
build {
dependsOn(shadowJar)
}
shadowJar {
archiveFileName.set("${project.name}-${project.version}.jar")
}
publishing {
repositories {
maven {
name = "GitHubPackages"
url = "https://maven.pkg.github.com/skycavemc/skycavelib"
credentials {
username = localProperties.getProperty("gpr.user") ?: System.getenv("GITHUB_ACTOR")
password = localProperties.getProperty("gpr.token") ?: System.getenv("ACCESS_TOKEN")
}
}
}
publications {
library(MavenPublication) {
from components.java
}
}
}
Solution
I did some more research and found a hint that shadowed jars might not work well. I removed this part
build {
dependsOn(shadowJar)
}
from the build.gradle of my library and published it to the package repository. Everything works fine since then, seems like that was the issue.
Exactly what the title says. For the record, I am using OpenJDK 15.0.1 and Gradle 6.7. I am trying to run code in a subproject with dependencies. When I try, I get a compiler error like so:
> Task :browser-core:compileJava FAILED
1 actionable task: 1 executed
(user profile)\IdeaProjects\cssbox-js-browser\browser-core\src\main\java\module-info.java:3: error: module not found: javafx.graphics
requires javafx.graphics;
^
(user profile)\IdeaProjects\cssbox-js-browser\browser-core\src\main\java\module-info.java:5: error: module not found: net.sf.cssbox
requires net.sf.cssbox;
^
(user profile)\IdeaProjects\cssbox-js-browser\browser-core\src\main\java\module-info.java:6: error: module not found: net.sf.cssbox.jstyleparser
requires net.sf.cssbox.jstyleparser;
^
As far as I'm concerned, the dependencies in question (JavaFX, CSSBox) are already specified under the root build.gradle file. Why does the compiler overlook these dependencies, and how do I fix it?
For reference, here's my root build.gradle:
plugins {
id 'java'
}
group 'org.example'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
java {
modularity.inferModulePath = true
}
allprojects {
plugins.withType(JavaPlugin, {
dependencies {
//determine dependency names
def os = org.gradle.internal.os.OperatingSystem.current()
def fxDep = ""
if (os.isWindows()) {
fxDep = "win"
}
else if (os.isMacOsX()) {
fxDep = "mac"
}
else if (os.isLinux()) {
fxDep = "linux"
}
//implementation 'org.slf4j:slf4j-jdk14:1.7.30'
implementation 'org.slf4j:slf4j-nop:1.7.30'
implementation('net.sf.cssbox:cssbox:5.0.0') {
exclude group: 'xml-apis', module: 'xml-apis'
}
implementation "org.openjfx:javafx-base:15.0.1:${fxDep}"
implementation "org.openjfx:javafx-controls:15.0.1:${fxDep}"
implementation "org.openjfx:javafx-graphics:15.0.1:${fxDep}"
implementation "org.openjfx:javafx-fxml:15.0.1:${fxDep}"
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.1'
}
})
}
test {
useJUnitPlatform()
}
and the subproject's build.gradle:
plugins {
id 'application'
}
group 'io.github.jgcodes'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
test {
useJUnitPlatform()
}
It turns out that
java {
modularity.inferModulePath = true;
}
needs to be set for all subprojects individually. Specifically, you need to place it in the allprojects closure.
I have a Jave 8, SpringBoot, webService which has been running fine on Eclipse 2020-06 for months. I build using Gradle. In an attempt to get the latest version of an updated jar file from Artifactory I did :
gradlew clean
gradlew eclipse
F5 (Refresh)
This indeed pulled the required jar file but my program now failed to compile. The error is:
The import org.springframework.beans.factory.annotation cannot be resolved
And all my #Autowired commands now error.
What i've tried :
gradlew cleanEclipse eclipse
close project, close eclipse, reopen eclipse, reopen project
gradle -> Refresh Gradle project
Same a 2. preceded by reboot pc. When I do this I get:
After I did:
gradlew cleanEclipse eclipse
The following jar dissapeared from my project:
spring-beans.5.3.0.RC1.jar
This is what is causing the problem.
Is this incorrect in build.gradle:
implementation "org.springframework:spring-beans:5.+"
How do I get this jar back?
Any help appreciated.
My build.gradle file is:
plugins {
id 'org.springframework.boot' version '2.2.2.RELEASE'
id 'java'
}
repositories {
maven {
url "https://repo-int.xxxxxx.io/artifactory/cc-central"
}
maven {
url "https://code.lds.org/nexus/content/groups/main-repo"
}
maven {
url "${chemaxonRepositoryUrl}/libs-release"
credentials {
username = chemaxonRepositoryUser
password = chemaxonRepositoryPassword
}
}
}
ext {
archive_basename = "dcrws"
project_description = "Chemistry Workbench DcrWs"
springStarterVersion = '2.2.2.RELEASE'
// Jenkins/Environment Information
build_tag = System.getenv('BUILD_TAG') ?: "none"
build_by = System.getenv('NODE_NAME') ?: "none"
build_date = System.getenv('BUILD_TIMESTAMP') ?: "none"
build_system = System.getenv('JENKINS_HOME') ?: "none"
build_url = System.getenv('BUILD_URL') ?: "none"
build_user = System.getenv('USER') ?: "none"
}
// standard plugins
apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'io.spring.dependency-management'
def git_info = hasProperty('git_info') ? git_info : 'https://git.git/repo,00000000'
def full_version = hasProperty('app_version') ? app_version : '0.0.0'
group = 'com.clarivate.singularity.chemworkbench'
version = full_version
archivesBaseName = ext.archive_basename
sourceCompatibility = 1.8
targetCompatibility = 1.8
configurations {
developmentOnly
runtimeClasspath {
extendsFrom developmentOnly
}
}
// if master branch, use latest version of chemcur:cwbcommon, else use 0.0+ version
ext.cwbcommon_version = '1.+'
if ( full_version =~ /^0./) { ext.cwbcommon_version = '0.0+' }
ext.pwbcommon_version = '1.+'
if ( full_version =~ /^0./) { ext.pwbcommon_version = '0.0+' }
dependencies {
implementation "org.springframework.boot:spring-boot-starter-actuator:$springStarterVersion"
implementation "org.springframework.boot:spring-boot-starter-web:$springStarterVersion"
implementation "org.springframework.boot:spring-boot-starter-cache:$springStarterVersion"
implementation "org.springframework.boot:spring-boot-starter-data-jdbc:$springStarterVersion"
implementation "org.springframework.boot:spring-boot-starter-data-jpa:$springStarterVersion"
implementation "org.springframework.boot:spring-boot-starter-tomcat:$springStarterVersion"
implementation 'com.fasterxml.jackson.core:jackson-core:2.+'
implementation "org.springframework:spring-beans:5.+"
implementation "org.springframework:spring-core:5.+"
implementation "javax.servlet:javax.servlet-api:4.+"
implementation "org.apache.commons:commons-lang3:3.9+"
implementation "commons-dbutils:commons-dbutils:1.7+"
implementation "com.oracle:ojdbc6:11.2.0.1.0"
compile 'com.chemaxon:calculations:20.+'
// homegrown libs
compile ("chemcur:cwbcommon:${cwbcommon_version}") {changing = true}
compile ("chemcur:pwbcommon:${pwbcommon_version}") {changing = true}
developmentOnly "org.springframework.boot:spring-boot-devtools:$springStarterVersion"
}
springBoot {
buildInfo {
properties {
artifact = archive_basename
version = full_version
group = group
name = project_description
additional = [
'Implementation-Title': project_description,
'Implementation-Version': full_version,
"Implementation-SCM": git_info,
"Jenkins-Build-Tag": build_tag,
"Build-By": build_by,
"Build-Date": build_date,
"Build-JDK": System.getProperty('java.version'),
"Build-Gradle-Version": project.gradle.gradleVersion,
]
}
}
}
so I've added a png img to my resources, since I want to use it in my project.
But Gradle seems not to let me build the project anymore, it's giving me the following error:
* What went wrong:
Execution failed for task ':processResources'.
> Could not copy file 'C:\workspace\Java\Utilities\EmailService\src\main\resources\img\watermark.png' to 'C:\workspace\Java\Utilities\EmailService\build\resources\main\img\watermark.png'.
Important part of Stacktrace is:
Caused by: groovy.lang.GroovyRuntimeException: Failed to parse template script (your template may contain an error or be trying to use expressions not currently supported): startup failed:
SimpleTemplateScript28.groovy: 4: illegal string body character after dollar sign;
solution: either escape a literal dollar sign "\$5" or bracket the value expression "${5}" # line 4, column 99.
o¿dHÌIDATx^Ý?╝$Eı┼Ù¥Ö┘]r♫↕$-↓$g%(êê
^
My setup of the project:
build.gradle:
import java.text.SimpleDateFormat
import org.apache.tools.ant.filters.ReplaceTokens
buildscript {
ext {
springBootVersion = '2.1.5.RELEASE'
set('springCloudVersion', 'Greenwich.RELEASE')
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
plugins {
id 'com.palantir.git-version' version '0.11.0'
}
def appName = 'EmailService'
version = '1.1.5'
group = 'dk.xx.email'
if (!hasProperty('mainClass')) {
ext.mainClass = 'dk.xx.email.EmailApplication'
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'maven-publish'
apply plugin: 'com.palantir.git-version'
sourceCompatibility = 1.8
repositories {
maven {
credentials {
username XXX
password XXXXXXX
}
url 'http://maven01.local:8080/repository/XX/'
}
mavenCentral()
maven { url 'https://jitpack.io' }
}
bootJar {
baseName = "${appName}"
version = "${version}"
}
dependencies {
compile('net.sf.jt400:jt400:9.5:jt400_jdk8')
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('org.springframework.boot:spring-boot-starter-data-rest')
compile('org.springframework.boot:spring-boot-starter-actuator')
compile group: 'org.springframework', name: 'spring-mock', version: '2.0.8'
compile group: 'org.springframework.cloud', name: 'spring-cloud-starter-netflix-eureka-client', version: '2.1.0.RELEASE'
compile group: 'org.springframework.cloud', name: 'spring-cloud-starter-openfeign', version: '2.1.0.RELEASE'
compile group: 'xx', name: 'NhoData-Entities', version: '0.1.99'
compile group: 'xx', name: 'xx-Entities', version: '2.1.7'
compile('dk.xx.stakeholder.document.archive:DocumentArchive:1.1.10:proxy')
compile group: 'com.itextpdf', name: 'itext7-core', version: '7.0.4'
compile('dk.xx.gui.start:EngagementGui:1.2.2:proxy')
compileOnly("org.projectlombok:lombok:1.18.6")
annotationProcessor group: 'org.springframework.boot', name: 'spring-boot-configuration-processor'
annotationProcessor 'org.projectlombok:lombok:1.18.6'
testCompile('org.springframework.boot:spring-boot-starter-test')
compile('org.springframework.boot:spring-boot-starter-mail')
compile('org.springframework.boot:spring-boot-starter-thymeleaf')
// Auto-produce swagger
compile group: 'io.springfox', name: 'springfox-swagger2', version: '2.9.2'
compile group: 'io.springfox', name: 'springfox-swagger-ui', version: '2.9.2'
}
task versionTxt() {
doLast {
def versionFile = new File("$projectDir/.ci/version.txt");
versionFile.getParentFile().mkdir();
versionFile.text = """
Version=$version
BuildTime=${new SimpleDateFormat("dd-MM-yyyy HH:mm:ss").format(new Date())}
ApplicationName=${appName}
"""
}
}
def dependencyName = "${appName}-proxy-${version}"
task tJar(type: Jar, dependsOn: compileJava) {
archiveName = "${dependencyName}.jar"
classifier = 'proxy'
from(sourceSets.main.output) {
includeEmptyDirs=false
include '**/feign/*'
include '**/domain/*'
include '**/entities/*'
}
}
task sourcesJar(type: Jar) {
classifier = 'sources'
from sourceSets.main.allJava
}
publishing {
publications {
maven(MavenPublication) {
artifacts {
groupId "${group}"
artifactId "${appName}"
version "${version}"
}
artifact tJar
artifact sourcesJar
}
repositories.maven {
url 'http://maven01.local:8080/repository/xx/'
credentials {
username xx
password xxxxxxxx
}
}
}
}
processResources {
filter(ReplaceTokens, tokens:[gitVersion: gitVersion()])
expand(project.properties)
}
static def buildTime() {
final dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
dateFormat.timeZone = TimeZone.getTimeZone('UTC')
dateFormat.format(new Date())
}
springBoot {
// This statement tells the Gradle Spring Boot plugin to generate a file
// build/resources/main/META-INF/build-info.properties
// that is picked up by Spring Boot to display via /actuator/info endpoint.
buildInfo {
// Generate extra build info.
properties {
def details = versionDetails()
additional = [
by : System.properties['user.name'],
time : buildTime(),
operatingSystem : "${System.properties['os.name']} (${System.properties['os.version']})",
machine : InetAddress.localHost.hostName,
ci_enabled : System.getenv('CI') ? true : false,
ci_buildNumber : System.env.'BUILD_NUMBER' ?: 'UNKNOWN',
ci_jobName : System.env.'JOB_NAME' ?: 'UNKNOWN',
appVersion : version
]
}
}
}
I think it's the filter statement in your processResources config. You're asking Gradle to replace text inside the PNG, but it can't make sense of the text in the PNG (which is because there is no text in it; probably doesn't conform to any reasonable character encoding).
I am trying to publish war files to our local artifactory server but when I run:
./gradlew clean build artifactoryPublish
I receive the following output:
:zuul-netflix-webapp:artifactoryPublish
Skipping task ':zuul-netflix-webapp:artifactoryPublish' as task onlyIf is false.
:zuul-netflix-webapp:artifactoryPublish SKIPPED
I've tried manually setting the onlyIf to true but this had no effect. I have tried similar configuration on another project and it works fine.
My environment:
17:22 $ ./gradlew --version
------------------------------------------------------------
Gradle 3.5.1
------------------------------------------------------------
Build time: 2017-06-16 14:36:27 UTC
Revision: d4c3bb4eac74bd0a3c70a0d213709e484193e251
Groovy: 2.4.10
Ant: Apache Ant(TM) version 1.9.6 compiled on June 29 2015
JVM: 1.8.0_141 (Oracle Corporation 25.141-b15)
OS: Mac OS X 10.11.6 x86_64
My build.gradle file looks like:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.netflix.nebula:gradle-extra-configurations-plugin:2.2.0'
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:latest.release"
classpath 'org.akhikhl.gretty:gretty:2.0.0'
}
configurations.classpath {
resolutionStrategy {
cacheDynamicVersionsFo r 0, 'seconds'
cacheChangingModulesFor 0, 'seconds'
}
}
}
plugins {
id 'nebula.netflixoss' version '3.4.0'
}
ext.githubProjectName = rootProject.name
configurations.all {
// Exclude old asm 3.x versions.
exclude group: 'asm', module: 'asm'
exclude group: 'asm', module: 'asm-all'
}
allprojects {
apply plugin: 'java'
group = "com.netflix.${githubProjectName}"
version = currentVersion
//status = 'Integration'
}
artifactoryPublish.skip = true
subprojects {
artifactoryPublish.skip = false
//artifactoryPublish.onlyIf { true }
apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'maven-publish'
apply plugin: 'ivy-publish'
apply plugin: 'war'
apply plugin: 'com.jfrog.artifactory'
apply plugin: 'nebula.netflixoss'
apply plugin: 'nebula.provided-base'
dependencies {
testCompile 'junit:junit:4.7'
}
repositories {
jcenter()
}
sourceCompatibility = '1.7'
targetCompatibility = '1.7'
sourceSets.test.java.srcDir 'src/main/java'
tasks.withType(Javadoc).each {
it.classpath = sourceSets.main.compileClasspath
}
test {
forkEvery = 1
maxParallelForks = 1
}
publishing {
publications {
mavenJava(MavenPublication) {
from components.web
}
}
}
artifactoryPublish {
skip = false
publications(publishing.publications.mavenJava)
}
}
artifactory {
//clientConfig.setIncludeEnvVars(true)
//clientConfig.info.addEnvironmentProperty('test.adding.dynVar',new java.util.Date().toString())
contextUrl = 'https://artifactory.oss.central1.com/artifactory'
publish {
repository {
repoKey = 'libs-snapshot-local' // The Artifactory repository key to publish to
username = "${artifactory_user}" // The publisher user name
password = "${artifactory_password}" // The publisher password
ivy {
ivyLayout = '[organization]/[module]/ivy-[revision].xml'
artifactLayout = '[organization]/[module]/[revision]/[module]-[revision](-[classifier]).[ext]'
mavenCompatible = true //Convert any dots in an [organization] layout value to path separators, similar to Maven's groupId-to-path conversion. True if not specified
}
}
defaults {
// Reference to Gradle publications defined in the build script.
// This is how we tell the Artifactory Plugin which artifacts should be
// published to Artifactory.
publications('mavenJava')
}
}
resolve {
repoKey = 'jcenter'
}
}