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']
}
}
}
Related
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?
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 multiproject GWt Gradle where the compileGwt from gradle does not find a subproject but if I use the standard Eclipse GWT plugin it compiles fine
When building through gradle I get the following error
:main:compileGwt
Loading inherited module 'com.stratebo.gwt.client.main.MainPage'
Loading inherited module 'com.stratebo.gwt.common'
[ERROR] Unable to find 'com/stratebo/gwt/common.gwt.xml' on your classpath; could be a typo, or maybe you forgot to include a classpath entry for source?
the project structure is as follows:
TMSRoot
|--settings.gradle
|--build.gradle
|--CommonGwt
|----build.gradle
|--main
|----build.gradle
The Tms Root settings.gradle
include "CommonGWT", "main"
The TmsRoot build.gradle
subprojects {
apply plugin: 'java'
apply plugin: 'eclipse'
repositories {
mavenCentral()
}
dependencies {
testCompile 'junit:junit:4.8.2'
}
version = '1.0'
jar {
manifest.attributes provider: 'Stratebo Technologies'
}
}
project('main'){
dependencies {
compile project(":CommonGWT")
}
}
The CommonGWT build.gradle
apply plugin: 'war'
apply plugin: 'java'
apply plugin: 'gwt'
apply plugin: 'eclipse'
apply plugin: 'jetty'
dependencies {
compile 'org.slf4j:slf4j-api:1.7.12'
testCompile 'junit:junit:4.12'
}
sourceCompatibility = 1.7
targetCompatibility = 1.7
version = '1.0'
buildscript {
repositories {
jcenter() //repository where to fetch gwt gradle plugin
}
dependencies {
classpath 'de.richsource.gradle.plugins:gwt-gradle-plugin:0.6'
classpath files(project(":CommonGWT").sourceSets.main.java.srcDirs)
}
}
repositories {
mavenCentral()
}
compileJava{
options.incremental = true
}
gwt {
gwtVersion='2.7.0'
modules 'com.stratebo.gwt.common'
sourceSets {
main {
java {
srcDir 'src'
}
}
}
logLevel = 'ERROR'
minHeapSize = "512M";
maxHeapSize = "1024M";
superDev {
noPrecompile=true
}
Eclipse.
eclipse{
addGwtContainer=false // Default set to true
}
jettyRunWar.httpPort = 8089
}
task wrapper(type: Wrapper) {
gradleVersion = '2.8'
}
The main build.gradle
apply plugin: 'war'
apply plugin: 'java'
apply plugin: 'gwt'
apply plugin: 'eclipse'
apply plugin: 'jetty'
dependencies {
compile 'org.slf4j:slf4j-api:1.7.12'
testCompile 'junit:junit:4.12'
}
sourceCompatibility = 1.7
targetCompatibility = 1.7
version = '1.0'
dependencies{
compile group: 'commons-collections', name: 'commons-collections', version: '3.2'
compile group: 'commons-codec', name: 'commons-codec', version: '1.5'
compile group: 'org.gwtbootstrap3', name: 'gwtbootstrap3', version: '0.9.1'
compile group: 'junit', name: 'junit', version: '4.11'
compile project(':CommonGWT')
testCompile group: 'junit', name: 'junit', version: '4.+'
}
def platformSources() {
return files('../CommonGWT/src/main/java', '../CommonGWT/src/main/resources')
}
buildscript {
repositories {
jcenter() //repository where to fetch gwt gradle plugin
}
dependencies {
classpath 'de.richsource.gradle.plugins:gwt-gradle-plugin:0.6'
}
}
repositories {
mavenCentral()
}
compileJava{
options.incremental = true
}
gwt {
gwtVersion='2.7.0'
modules 'com.stratebo.gwt.client.main.MainPage'
sourceSets {
main {
java {
srcDir 'src'
}
}
}
logLevel = 'ERROR'
minHeapSize = "512M";
maxHeapSize = "1024M";
superDev {
noPrecompile=true
}
eclipse{
addGwtContainer=false // Default set to true
}
//Specify the deployment Port
jettyRunWar.httpPort = 8089
}
task wrapper(type: Wrapper) {
gradleVersion = '2.8'
}
the CommonGWt common.gwt.xml file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 2.6.1//EN" "http://google-web-toolkit.googlecode.com/svn/tags/2.6.1/distro-source/core/src/gwt-module.dtd">
<module>
<inherits name="com.google.gwt.user.User" />
<inherits name="com.stratebo.gwt.common" />
<source path="client" />
<source path="common" />
</module>
And finally the Main MainPage.gwt.xml
<module>
<inherits name="org.gwtbootstrap3.GwtBootstrap3NoTheme" />
<inherits name="com.google.gwt.user.User" />
<stylesheet src="/mytheme.cache.css" />
<entry-point class="com.stratebo.gwt.client.main.MainPage">
</entry-point>
<inherits name="com.stratebo.gwt.common" />
<source path="client" />
<source path="common" />
</module>
any help greatly appreciated
I think that you you are missing the sources from your commonGWT project that you could add to your jar commonGWT build.gradle :
jar {
from sourceSets.main.allSource
}
The commonGWT jar will contain the sources that will allow the compilation of the dependent project.
I have a following structure .
I am constructing build.gradle by copy-paste from numerous sources..
buildscript {
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.bmuschko:gradle-tomcat-plugin:2.2.2'
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'war'
apply plugin: 'com.bmuschko.tomcat'
webAppDirName = 'WebContent'
repositories {
jcenter()
mavenCentral()
}
sourceSets {
main {
// where does the Java source code live?
java {
srcDir 'src'
}
// where do classpath resources like *.properties files live?
resources {
srcDir 'src/main/resources'
}
}
}
sourceCompatibility = 1.7
targetCompatibility = 1.7
dependencies {
testCompile("junit:junit")
compile fileTree(dir: 'WebContent/WEB-INF/lib', include: ['*.jar'])
String tomcatVersion = '7.0.52'
tomcat "org.apache.tomcat.embed:tomcat-embed-core:${tomcatVersion}"
tomcat "org.apache.tomcat.embed:tomcat-embed-logging-juli:${tomcatVersion}"
tomcat("org.apache.tomcat.embed:tomcat-embed-jasper:${tomcatVersion}") {
exclude group: 'org.eclipse.jdt.core.compiler', module: 'ecj'
}
}
task wrapper(type: Wrapper) {
gradleVersion = '2.3'
}
tomcat {
contextPath = '/'
}
when I run gradle tomcatRun, I see the following output
02:49:58.819 [QUIET]
[com.bmuschko.gradle.tomcat.embedded.BaseTomcatServerImpl$AfterStartEventLifecycleListener]
Started Tomcat Server 02:49:58.820 [QUIET]
[com.bmuschko.gradle.tomcat.embedded.BaseTomcatServerImpl$AfterStartEventLifecycleListener]
The Server is running at http://localhost:8080
Building 75% > :tomcatRun
But when I connect to http://localhost:8080 I see either 404 error or blank page..