below is my build.gradle
plugins {
id 'org.springframework.boot' version '2.7.5'
id 'io.spring.dependency-management' version '1.0.15.RELEASE'
id 'java'
id 'eclipse'
id 'jacoco'
id 'org.sonarqube' version "3.3"
id 'com.google.cloud.tools.jib' version "${jibVersion}"
}
group = 'com.vsi.postgrestoattentive'
if (!project.hasProperty('buildName')) {
throw new GradleException("Usage for CLI:"
+ System.getProperty("line.separator")
+ "gradlew <taskName> -Dorg.gradle.java.home=<java-home-dir> -PbuildName=<major>.<minor>.<buildNumber> -PgcpProject=<gcloudProject>"
+ System.getProperty("line.separator")
+ "<org.gradle.java.home> - OPTIONAL if available in PATH"
+ System.getProperty("line.separator")
+ "<buildName> - MANDATORY, example 0.1.23")
+ System.getProperty("line.separator")
+ "<gcpProject> - OPTIONAL, project name in GCP";
}
project.ext {
buildName = project.property('buildName');
}
version = "${project.ext.buildName}"
sourceCompatibility = '1.8'
apply from: 'gradle/sonar.gradle'
apply from: 'gradle/tests.gradle'
apply from: 'gradle/image-build-gcp.gradle'
repositories {
mavenCentral()
}
dependencies {
implementation("org.springframework.boot:spring-boot-starter-web:${springBootVersion}")
implementation("org.springframework.boot:spring-boot-starter-actuator:${springBootVersion}")
implementation 'org.springframework.boot:spring-boot-starter-web:2.7.0'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.integration:spring-integration-test'
testImplementation 'org.springframework.batch:spring-batch-test:4.3.0'
implementation("org.springframework.boot:spring-boot-starter-data-jpa:${springBootVersion}")
implementation 'org.postgresql:postgresql:42.1.4'
implementation 'org.springframework.batch:spring-batch-core:4.1.1.RELEASE'
implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.14.1'
implementation group: 'io.micrometer', name: 'micrometer-registry-datadog', version: '1.7.0'
}
bootJar {
archiveFileName = "${project.name}.${archiveExtension.get()}"
}
springBoot {
buildInfo()
}
test {
finalizedBy jacocoTestReport
}
jacoco {
toolVersion = "0.8.8"
}
jacocoTestReport {
dependsOn test
}
We use javax.persistence.Tuple in our code for fetching data from postgres.It works fine but as soon as i change springboot version from '2.7.5' to '2.3.4.RELEASE' i get following error
java.lang.IllegalArgumentException: Invoked method public abstract java.lang.Object javax.persistence.Tuple.get(java.lang.String) is no accessor method!
at org.springframework.data.projection.Accessor.(Accessor.java:50) ~[spring-data-commons-2.3.4.RELEASE.jar!/:2.3.4.RELEASE]
Can someone please help me out here?
Related
Currently I'm stuck with automatically added built source files after compiled.
QueryDSL IS WORKING (automatically added after refresh.).
However, MapStruct is not working.
QueryDSL Output is src/main/generated/querydsl, each of projects.
MapStruct is default (build/generated/sources/annotationProcessor/java/main) on their projects.
After add source files manually, this code is works, But I want to add source automatically like querydsl.
here is my part of build.gradle.
// Root build.gradle
buildscript {
ext {
springBootVersion = '2.7.2'
dependencyManagementVersion = '1.0.12.RELEASE'
mysqlVersion = '8.0.30'
lombokVersion = '6.5.0.3'
queryDslVersion = '4.4.0'
queryDslPluginVersion = '1.0.10'
mapStructVersion = '1.5.3.Final'
lombokMapstructBindingVersion = "0.2.0"
}
repositories {
mavenCentral()
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}"
classpath "io.spring.gradle:dependency-management-plugin:${dependencyManagementVersion}"
classpath "io.freefair.gradle:lombok-plugin:${lombokVersion}"
// for QueryDSL
classpath "gradle.plugin.com.ewerk.gradle.plugins:querydsl-plugin:${queryDslPluginVersion}"
}
}
subprojects {
group = 'test.test'
version '0.0.1-SNAPSHOT'
apply plugin: 'java'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'io.freefair.lombok'
apply plugin: 'com.ewerk.gradle.plugins.querydsl'
sourceCompatibility = '11'
repositories {
mavenCentral()
}
dependencies {
compile group: 'com.querydsl', name: 'querydsl-jpa'
annotationProcessor group: 'com.querydsl', name: 'querydsl-apt'
// for QueryDSL
// implementation "com.querydsl:querydsl-core:${queryDslVersion}"
// implementation "com.querydsl:querydsl-jpa:${queryDslVersion}"
// annotationProcessor "com.querydsl:querydsl-apt:${queryDslVersion}:jpa"
annotationProcessor "jakarta.persistence:jakarta.persistence-api"
annotationProcessor "jakarta.annotation:jakarta.annotation-api"
annotationProcessor "org.mapstruct:mapstruct-processor:${mapStructVersion}"
implementation "org.mapstruct:mapstruct:${mapStructVersion}"
annotationProcessor "org.projectlombok:lombok-mapstruct-binding:${lombokMapstructBindingVersion}"
testImplementation 'junit:junit:4.12'
}
}
// for QueryDSL
task cleanGeneatedDir(type: Delete) {
delete file('src/main/generated')
}
// A Project build.gradle
dependencies {
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-web'
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-security'
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-validation'
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa'
implementation group: 'org.springdoc', name: 'springdoc-openapi-ui', version: '1.6.11'
implementation 'com.querydsl:querydsl-jpa:4.4.0'
testImplementation group: 'org.springframework.boot', name: 'spring-boot-starter-test'
}
def querydslDir = "src/main/generated/querydsl"
querydsl {
library = "com.querydsl:querydsl-apt"
jpa = true
querydslSourcesDir = querydslDir
}
sourceSets {
main.java.srcDir querydslDir
}
compileQuerydsl{
options.annotationProcessorPath = configurations.querydsl
}
configurations {
compileOnly {
extendsFrom annotationProcessor
}
querydsl.extendsFrom compileClasspath
}
It automatically configured by sourceSets > main > java > srcDirs in gradle.
in codes,
sourceSets {
main {
java {
srcDirs = ['src/main/java', 'build/generated/sources/annotationProcessor/java/main']
}
}
}
With Flyway version 7.5.0, it still works fine. Version 7.5.1 and 7.5.2 however, produce the following error:
[...]
java.lang.IllegalStateException: Unexpected error occurred while initializing the data source
at com.google.common.base.Preconditions.checkState(Preconditions.java:459)
at io.zonky.test.db.flyway.DefaultFlywayDataSourceContext.getTarget(DefaultFlywayDataSourceContext.java:89)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:195)
at com.sun.proxy.$Proxy65.getConnection(Unknown Source)
at org.flywaydb.core.internal.jdbc.JdbcUtils.openConnection(JdbcUtils.java:59)
at org.flywaydb.core.internal.jdbc.JdbcConnectionFactory.<init>(JdbcConnectionFactory.java:69)
at org.flywaydb.core.Flyway.execute(Flyway.java:507)
at org.flywaydb.core.Flyway.migrate(Flyway.java:165)
at org.springframework.boot.autoconfigure.flyway.FlywayMigrationInitializer.afterPropertiesSet(FlywayMigrationInitializer.java:66)
[...]
Any idea, what's the problem or how to fix it?
Below is the code of my minimal example to reproduce the problem:
Dockerfile
FROM openjdk:11.0.10-jdk AS base
# Needed for embedded PostgreSQL-server to start during integration tests.
# see: https://github.com/zonkyio/embedded-database-spring-test
RUN groupadd --system --gid 1000 test
RUN useradd --system --gid test --uid 1000 --shell /bin/bash --create-home test
USER test
WORKDIR /home/test
ADD . /home/test/
RUN ./gradlew test
build.gradle
buildscript {
ext {
kotlinVersion = '1.4.21'
springBootVersion = '2.4.2'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${kotlinVersion}")
classpath("org.jetbrains.kotlin:kotlin-allopen:${kotlinVersion}")
classpath("org.jetbrains.kotlin:kotlin-noarg:${kotlinVersion}")
}
}
apply plugin: 'kotlin'
apply plugin: 'kotlin-spring'
apply plugin: 'kotlin-jpa'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
group = 'com.acme'
version = '1.0.0-SNAPSHOT'
sourceCompatibility = 1.8
compileKotlin {
kotlinOptions {
freeCompilerArgs = ["-Xjsr305=strict"]
jvmTarget = "1.8"
}
}
compileTestKotlin {
kotlinOptions {
freeCompilerArgs = ["-Xjsr305=strict"]
jvmTarget = "1.8"
}
}
repositories {
mavenCentral()
}
dependencies {
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa', version: "${springBootVersion}"
implementation group: 'org.postgresql', name: 'postgresql', version: '42.2.18'
implementation group: 'org.flywaydb', name: 'flyway-core', version: '7.5.2'
implementation group: 'org.jetbrains.kotlin', name: 'kotlin-reflect', version: "${kotlinVersion}"
testImplementation group: 'org.springframework.boot', name: 'spring-boot-starter-test', version: "${springBootVersion}"
testImplementation group: 'junit', name: 'junit', version: '4.13.1'
testImplementation group: 'io.zonky.test', name: 'embedded-database-spring-test', version: '1.6.2'
}
test {
testLogging {
exceptionFormat = 'full'
}
}
compileKotlin.dependsOn(processResources)
compileJava.dependsOn(processResources)
settings.gradle
rootProject.name = 'flywayzonkytest'
src/main/kotlin/com/acme/flywayzonkytest/Application.kt
package com.acme.flywayzonkytest
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication
#SpringBootApplication
class Application
fun main(args: Array<String>) {
runApplication<Application>(*args)
}
src/main/resources/application.yml
spring:
flyway:
enabled: true
src/main/resources/db/migration/V1__thing.sql
CREATE TABLE thing (
some_id BIGINT PRIMARY KEY NOT NULL,
some_name VARCHAR NOT NULL
);
src/test/kotlin/com/acme/flywayzonkytest/integration/CreateContextTest.kt
package com.acme.flywayzonkytest.integration
import io.zonky.test.db.AutoConfigureEmbeddedDatabase
import org.junit.Test
import org.junit.runner.RunWith
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.test.context.junit4.SpringRunner
#RunWith(SpringRunner::class)
#AutoConfigureEmbeddedDatabase
#SpringBootTest
class CreateContextTest {
#Test
fun `test create context`() {
}
}
Flyway had some breaking changes between version 7.5.0 and 7.5.1. The maintainer of zonkyio/embedded-database-spring-test just implemented a fix/workaround in his library, which is included in version 1.6.3. :-)
I use gradle for building and want to generate some scala code for protobuf using this plugin: https://github.com/CharlesAHunt/scalapb-gradle-plugin
My gradle.build:
group 'xxxx'
version '1.0-SNAPSHOT'
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "gradle.plugin.com.charlesahunt:scalapb-plugin:1.2.4"
}
}
repositories {
mavenCentral()
}
apply plugin: 'com.charlesahunt.scalapb'
apply plugin: 'java'
apply plugin: 'scala'
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencies {
implementation 'org.scala-lang:scala-library:2.12.8'
compile group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.3'
compile group: 'com.typesafe', name: 'config', version: '1.3.4'
testCompile group: 'org.scalatest', name: 'scalatest_2.12', version: '3.0.8'
}
scalapbConfig {
protocVersion = "-v360"
grpc = false
targetDir = "build/generated/scala"
projectProtoSourceDir = "src/main/protobuf"
extractedIncludeDir = "build/external_protos"
}
sourceSets {
generated {
scala.srcDirs += "build/generated/"
}
}
compileScala {
dependsOn scalapb
}
The problem is that generated code isn't visible for my code and i can't use it. I tried to change targetDir and scala.srcDirs but it didn't help.
How can i solve this problem?
p.s. i use IntelliJ
I have a simple setup with gradle and Open Liberty. From this blogpost https://openliberty.io/blog/2018/12/14/microprofile21-18004.html
it says
"Open Liberty now has reactive extensions to JAX-RS 2.1 so that you can use providers from Apache CXF and Jersey"
But I can't get it to work with Jersey
I've tried various configurations of my build.gradle file and server.xml but still can't get it to work and find documentation lacking.
build.gradle
apply plugin: 'war'
apply plugin: 'liberty'
apply plugin: 'java-library'
group = 'x.y.z'
version = '1.0-SNAPSHOT'
description = "X Y Z"
sourceCompatibility = 1.8
targetCompatibility = 1.8
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'net.wasdev.wlp.gradle.plugins:liberty-gradle-plugin:2.6.3'
}
}
repositories {
mavenCentral()
}
//required for compiling, testing and running the application
dependencies {
implementation group: 'org.glassfish.jersey.core', name: 'jersey-client', version: '2.26'
implementation group: 'org.glassfish.jersey.core', name: 'jersey-common', version: '2.26'
implementation group: 'org.glassfish.jersey.core', name: 'jersey-server', version: '2.26'
providedCompile group:'javax.servlet', name:'javax.servlet-api', version:'3.1.0'
testCompile group:'commons-httpclient', name:'commons-httpclient', version:'3.1'
testCompile group:'junit', name:'junit', version:'4.12'
libertyRuntime group:'io.openliberty', name:'openliberty-runtime', version:'19.0.0.3'
// This dependency is exported to consumers, that is to say found on their compile classpath.
api 'org.apache.commons:commons-math3:3.6.1'
// This dependency is used internally, and not exposed to consumers on their own compile classpath.
implementation 'com.google.guava:guava:27.0.1-jre'
testImplementation 'junit:junit:4.12'
}
//Extra properties for project level
ext {
appName = project.name
testServerHttpPort = 9080
testServerHttpsPort = 9443
warContext = appName
}
liberty {
server {
name = "${appName}Server"
configFile = file("src/main/liberty/config/server.xml")
bootstrapProperties = ['default.http.port': testServerHttpPort,
'default.https.port': testServerHttpsPort,
'app.context.root': warContext]
packageLiberty {
archive = "$buildDir/${appName}.zip"
include = "usr"
}
}
}
war {
archiveName = "${baseName}.${extension}"
}
//unit test configuration
test {
reports.html.destination = file("$buildDir/reports/unit")
reports.junitXml.destination = file("$buildDir/test-results/unit")
exclude '**/it/**'
}
//integration test configuration
task integrationTest(type: Test) {
group 'Verification'
description 'Runs the integration tests.'
reports.html.destination = file("$buildDir/reports/it")
reports.junitXml.destination = file("$buildDir/test-results/it")
include '**/it/**'
exclude '**/unit/**'
systemProperties = ['liberty.test.port': testServerHttpPort, 'war.name': warContext]
}
task openBrowser {
description = 'Open browser to http://localhost:8080/${warContext}'
doLast {
java.awt.Desktop.desktop.browse
"http://localhost:${testServerHttpPort}/${appName}".toURI()
}
}
task openTestReport {
description = 'Open browser to the test report'
doLast {
java.awt.Desktop.desktop.browse file("$buildDir/reports/it/index.html").toURI()
}
}
clean.dependsOn 'libertyStop'
check.dependsOn 'integrationTest'
integrationTest.dependsOn 'libertyStart'
integrationTest.finalizedBy 'libertyStop'
integrationTest.finalizedBy 'openTestReport'
libertyPackage.dependsOn 'libertyStop'
server.xml
<?xml version="1.0" encoding="UTF-8"?>
<server description="new server">
<featureManager>
<!-- <feature>jsp-2.3</feature> -->
<!-- <feature>jaxrs-2.1</feature> -->
<feature>servlet-4.0</feature>
<!--
-->
</featureManager>
<httpEndpoint id="defaultHttpEndpoint"
httpPort="${default.http.port}"
httpsPort="${default.https.port}" />
<applicationManager autoExpand="true"/>
<webApplication contextRoot="${app.context.root}" location="${app.context.root}.war" />
</server>
HelloWorldService
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.Response;
#Path("/hello")
public class HelloWorldService {
#GET
#Path("/{param}")
public Response getMsg(#PathParam("param") String msg) {
String output = "Jersey say : " + msg;
return Response.status(200).entity(output).build();
}
}
When I try to hit the endpoint I get a 404
curl localhost:9080/XYZ/hello/jersey
Error 404: java.io.FileNotFoundException: SRVE0190E: File not found: /hello/jersey
Any help MUCH appreciated!
to make it short: I am unable to shrink my more complex scala programs with Proguard. I think I am overlooking something, but currently I have no Idea what it could be.
My Current setup relys upon a build.gradle-file to shrink my compiled fat-jar.
import proguard.gradle.ProGuardTask
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'net.sf.proguard:proguard-gradle:5.2.1'
}
}
plugins {
id 'application'
id 'java'
id 'scala'
}
mainClassName = 'app.Main'
sourceCompatibility = 1.8
repositories {
...
}
dependencies {
...
}
jar {
manifest {
attributes(
'Class-Path': configurations.compileClasspath.files.collect {"$it.name"}.join(' '),
'Main-Class': 'app.Main'
)
}
from {
configurations.compileClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
}
task proguarding(type: ProGuardTask, dependsOn: jar) {
configuration 'proguard-rules.pro'
libraryjars files(configurations.compileClasspath.collect { it })
injars "$buildDir/libs/Main.jar"
outjars "$buildDir/libs/Shrunk.jar"
}
These are my proguard rules inside the proguard-rules.pro file
-keep class testing.** { *; }
-dontoptimize
-dontobfuscate
#-dontpreverify
#-dontnote
-ignorewarnings
-forceprocessing
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
-dontwarn scala.**
-keep class !scala*.** { *; }
-dontwarn **$$anonfun$*
-dontskipnonpubliclibraryclasses
-dontskipnonpubliclibraryclassmembers
-keep class ... # imagine like 5-thousend different keep-rules I tried
-keepclassmembers class * {
** MODULE$;
}
All the Programs/ Libs I tried to shrink so far didn't work after the shrinking.
Except for the most basic scala program:
package main
import java.io._
object Main extends App {
val pw = new PrintWriter(new File("hello.txt" ))
pw.write("Hello, world")
pw.close()
}
This one I could shrink from 5.5mb to 432kb, but everything else won't work and instead throws me run time errors like NullPointerExceptions or something about the stackmap.
Exception in thread "main" java.lang.VerifyError: Expecting a stackmap frame at branch target 14
Exception Details:
Location:
generator/Main$.parameters()Lscalafx/application/JFXApp$Parameters; #4: ifne
Reason:
Expected stackmap frame at this location.
Bytecode:
0x0000000: 2ab4 0010 9a00 0a2a b700 1ca7 0007 2ab4
0x0000010: 0011 b0
at generator.Main.main(Main.scala)
I found out, that these problems arose through the dontpreverify-option, but If I don't use "-dontpreverify", it won't even compile.
Without that option ProGuard is not able to find superclasses (just like this guy)
So I tried every keep-option I could find.
None of the solutions I found helped in any way. If anybody knows what's wrong, please help I am at the end of my nerves.
If somebody knows another shrinker for jar files that is actually easy to use, please tell me.
Btw, The GUI was even more confusing than the gradle plugin so, I ditched that approach
The mistake I made, was not to include the java runtime jar from the jdk
Here is the gradle with the proguarding task
import proguard.gradle.ProGuardTask
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'net.sf.proguard:proguard-gradle:6.0.3'
}
}
plugins { ... }
version '1.0'
mainClassName = 'app.Main'
sourceCompatibility = 1.8
repositories { ... }
dependencies { ... }
jar {
manifest {
attributes(
'Class-Path': configurations.compileClasspath.files.collect {"$it.name"}.join(' '),
'Main-Class': 'app.Main'
)
}
from {
configurations.compileClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
}
task proguarding(type: ProGuardTask, dependsOn: jar) {
configuration 'proguard-rules.pro'
libraryjars files(configurations.compileClasspath.collect { it })
injars "$buildDir\\libs\\" + project.name + "-" + version + ".jar"
outjars "$buildDir\\libs\\" + project.name + "-" + version + "_shrunk" + ".jar"
}
And here are the pro-guard rules inside proguard-rules.pro
-keep class app.** { *; }
#-dontoptimize
-dontobfuscate
#-dontnote
#-dontusemixedcaseclassnames
-ignorewarnings
-forceprocessing
-libraryjars C:/Program Files/Java/jdk1.8.0_181/jre/lib/rt.jar
-libraryjars C:/Program Files/Java/jdk1.8.0_181/jre/lib/ext/jfxrt.jar
Now I don't get any warnings and everything compiles just fine.