How to add generated sources for scala protobuf plugin using gradle? - scala

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

Related

Automatically Add built source files in STS 4?

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']
}
}
}

Spring Boot "Hello World" example gives run method exception

Before I recieve suggestive comments questioning my intelligence I will just go out and say that I just followed the guidance provided on official Spring website (https://spring.io/guides/gs/rest-service/). And as a reward I recieved an error.
Dont find it necessary to define anything that doesnt state in the documentation, Gradle build is copy-pasted, so where lies the problem?
build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:2.0.5.RELEASE")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
bootJar {
baseName = 'gs-rest-service'
version = '0.1.0'
}
repositories {
mavenCentral()
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencies {
compile("org.springframework.boot:spring-boot-starter-web")
testCompile('org.springframework.boot:spring-boot-starter-test')
}

Unable to import spring-boot gradle project in eclipse workspace

Gradle setup for Spring-boot application : build.gradle file i have used sourcesSet where my all java source file resides.
buildscript {
repositories {
//Required repos
mavenCentral()
maven { url "http://repo.spring.io/snapshot" }
maven { url "http://repo.spring.io/milestone" }
mavenLocal()
}
dependencies {
//Required dependency for spring-boot plugin
classpath 'org.springframework.boot:spring-boot-gradle-plugin:1.1.2.BUILD-SNAPSHOT'
}
}
apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'spring-boot'
apply plugin: 'eclipse-wtp'
bootRepackage {
mainClass = 'com.test.app.Application'
}
war {
baseName = 'companies'
version = '0.1'
}
repositories {
mavenCentral()
maven { url "http://repo.spring.io/snapshot" }
maven { url "http://repo.spring.io/milestone" }
mavenLocal()
}
dependencies {
compile 'org.springframework.boot:spring-boot-starter-web'
//Required dependency for JSP
providedRuntime 'org.apache.tomcat.embed:tomcat-embed-jasper'
}
sourceSets {
main {
java {
srcDir 'app/GeneratedSource'
srcDir 'app/JavaSource'
srcDir 'web/JavaSource'
}
resources {
srcDir 'app/GeneratedSource'
srcDir 'app/JavaSource'
srcDir 'web/JavaSource'
}
}
}
eclipse {
classpath {
defaultOutputDir = file('web/WebContent/WEB-INF/classes')
}
}
webAppDirName = 'web/WebContent'
libsDirName = 'war'
war {
baseName = baseName
version = appVersion
archiveName = warName
}
task printClasspath {
doLast {
configurations.testRuntime.each { println it }
}
enter image description hereCommand Line able to build model
When in eclipse while importing gradle project it is showing error
Iam unable to import Gradle project in Eclipse
Do you have a Gradle plugin for eclipse?
Help -> Eclipse MArketplace -> Search "Gradle" -> Install the Gradle STS integration.
In addition I recomend you change Spring Boot version to '1.3.3.RELEASE'.
buildscript {
ext {
springBootVersion = '1.3.3.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}}
In my case there was an update available for the gradle plugin. Once I updated the plugin using eclipse marketplace everything worked fine and project was imported properly.

Migrating from existing dynamic web project to gradle?

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..

Writing custom gradle plugin with non-transitive dependency

I am trying to implement a gradle plugin which in turn depends on an another gradle plugin. Here is a snippet of my plugin's build.gradle
buildscript {
repositories {
mavenCentral()
mavenLocal()
}
}
apply plugin: 'groovy'
apply plugin: 'idea'
apply plugin: 'maven'
dependencies {
repositories {
mavenCentral()
mavenLocal()
}
compile gradleApi()
compile localGroovy()
compile 'com.example:otherplugin:[0.1,)'
}
uploadArchives {
repositories {
mavenDeployer {
repository(url: mavenLocal())
pom.groupId = 'com.example'
pom.version = '0.5'
pom.artifactId = 'myplugin'
}
}
}
As you can see, I am using range dependency and not particular about any version of the 'otherplugin'. When the user includes my plugin in his build.gradle:
buildscript {
repositories {
mavenCentral()
mavenLocal()
}
dependencies {
classpath 'com.example:otherplugin:1.0', 'com.example:myplugin:2.3'
}
}
Gradle always uses the latest version of 'com.example:otherplugin' to process his project. Ideally, I would like the version specified by the user to be downloaded, and used by gradle.
I believe this is a problem with my plugin's build.gradle. How can I modify my plugin's build.gradle so that, this transitive dependency is avoided ?