I'm migrating a project to gradle to resolve dependencies, generate the eclipse project and build the project and I'm with a problem with the version of some dependencies on eclipse project. Here's the build.gradle of the project. It's an EAR with sub-projects.
apply plugin: 'ear'
def eclipseJbossName = 'org.eclipse.jst.server.core.container/org.jboss.ide.eclipse.as.core.server.runtime.runtimeTarget/JBoss 6.x Runtime'
def defaultEarConfig = rootDir.getAbsolutePath() + '/ear.gradle'
allprojects {
apply plugin: 'eclipse'
apply plugin: 'eclipse-wtp'
apply plugin: 'idea'
eclipse {
classpath {
containers eclipseJbossName
}
}
repositories {
maven {
name = "mvnrepository"
url = "http://mvnrepository.com/"
}
mavenCentral()
maven {
name = 'jboss'
url = 'http://repository.jboss.org/nexus/content/groups/public/'
}
}
}
subprojects {
configurations {
provided
}
apply plugin: 'java'
sourceCompatibility = 1.6
targetCompatibility = 1.6
sourceSets {
main {
compileClasspath += configurations.provided
compileClasspath += configurations.compile
compileClasspath += configurations.runtime
}
}
}
dependencies {
deploy (project(path: 'anEJB')) {
transitive = false
}
deploy (project(path: 'anotherEJB')) {
transitive = false
}
deploy (project(path: 'aWAR', configuration: 'archives')) {
transitive = false
}
earlib ('commons-beanutils:commons-beanutils:1.6') {
transitive = false
}
//lots of other dependencies and all with transitive=false
}
//configuration of my subprojects
When I call gradle ear it builds and generate my artifact correctly. In the lib directory inside the root of the EAR there's all my earlibs with its correct versions. When I call gradle cleanEclipse eclipse it generates my project right, but when I see the build path inside eclipse it is using an incorrect version for commons beanutils. It is using the version 1.8. This is not happening for all my dependencies, but there are others with this problem. I've put all to not resolve the transitive dependencies.
You can click the project in Eclipse with right mouse button, then click properties. And select "Java Build Path" then click "Libraries" tab. Finally remove all jars besides "Gradle Dependencies" & "JRE System Libraries".
Done. Try it.
Related
In order to not manually manage, both, Maven and Gradle build configuration files, I wanted to let Gradle generate the Maven POMs for a multi-module build.
This is working so far. Below you find the settings.gradle
rootProject.name = 'parent'
include 'module-a'
include 'module-b'
and here follows build.gradle
allprojects {
apply plugin: 'maven'
group = 'com.example.project'
version = '1.0-SNAPSHOT'
}
subprojects {
apply plugin: 'java'
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
}
task createPom << {
pom {
project {
parent {
groupId project.group
artifactId rootProject.name
version project.version
}
}
}.writeTo("pom.xml")
}
}
task createPom << {
pom {
project {
packaging 'pom'
modules {
module 'module-a'
module 'modula-b'
}
}
}.writeTo("pom.xml")
}
The problem is that I have to manually declare the modules in the createPom task of the root project. Also, I need two dedicated tasks; one for the root project and and for the subprojects.
How can I let Gradle figure out what the modules are? Or is there a way to programmatically determine and add the subprojects as modules? Furthermore, is it even necessary to have two distinct tasks?
I am trying to generate code for a simple protobuf example using the build instructions given here. I have been trying for awhile but I am not able to see any auto generated code in my source root.
The following is my build.gradle file
buildscript {
ext {
springBootVersion = '2.0.4.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath "io.spring.gradle:dependency-management-plugin:1.0.3.RELEASE"
classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.5'
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'com.google.protobuf'
group = 'io.ai.vivid'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencyManagement {
imports {
mavenBom 'com.amazonaws:aws-java-sdk-bom:1.11.228'
}
}
protobuf {
protoc {
artifact = "com.google.protobuf:protoc:3.5.1-1"
}
generateProtoTasks.generatedFilesBaseDir = 'generated-sources'
plugins {
grpc {
artifact = 'io.grpc:protoc-gen-grpc-java:1.14.0'
}
}
generateProtoTasks {
all()*.plugins {
grpc {}
}
}
}
dependencies {
compile 'io.grpc:grpc-netty-shaded:1.14.0'
compile 'io.grpc:grpc-protobuf:1.14.0'
compile 'io.grpc:grpc-stub:1.14.0'
}
Also in my build.gradle file IntelliJ complains that it cannot resolve name protobuf
Things I have tried
Sync gradle tool in IntelliJ. This is the most prominent solution
given in SO
Setting Build tools -> Gradle -> Runner -> Delelgate IDE build/run
actions on gradle to true
Clean rebuilding of the gradle project.
From my understanding of the GitHub post, when you use the protobuf plugin, the stub will be automatically generated for you. What am I missing?
You've applied idea plugin, but you didn't configure it. You need to tell idea plugin where to include the generated source code.
protobuf {
generatedFilesBaseDir = "$projectDir/src/generated"
}
idea {
module {
sourceDirs += file("${projectDir}/src/generated/main/java");
sourceDirs += file("${projectDir}/src/generated/main/grpc");
}
}
You can take a look
at a full example of a buildfile here: build.gradle
In case anyone else ends up here problems getting IntelliJ to recognise the generated sources (Red highlight imports , classes etc). Beware of the intellisense file size limit. If your generated protobuf code exceeds the default setitng of 2500KB then the file is ignored.
Got Help -> Edit custom properties and add an entry appropriate for your case e.g.
idea.max.intellisense.filesize=4000
Spent half a day faffing over different source set source folder, generated sources, and include / exclude directories. Turned out I just need to increase this value
Alternatively, you can use sourceSets:
sourceSets {
main {
java {
srcDirs 'build/generated/source/proto/main/grpc'
srcDirs 'build/generated/source/proto/main/java'
}
}
}
I am a gradle beginner and I am struggling to include the frontend distribution build folder in the backend jar (I use Spring Boot and the frontend is an ionic app). In the backend.gradle, I configured the jar-Task that should include the frontend-build folder (called www) into build folder of the backend. The jar task runs through, but the desired artifacts are not present in the backend-build folder and therefore not in the final jar. Would be glad for any help.
project structure:
project
build.gradle
settings.gradle
backend
--> backend.gradle
frontend
--> frontend.gradle
settings.gradle
include 'backend'
include 'frontend'
rootProject.children.each {
it.buildFileName = it.name + '.gradle'
}
build.gradle
allprojects {
buildscript {
repositories {
mavenCentral()
}
}
apply plugin: 'idea'
repositories {
mavenCentral()
}
}
frontend.gradle
plugins {
id "com.moowork.node" version "1.2.0"
}
task clean(dependsOn: 'npm_run_clean') {
}
task build(dependsOn: 'npm_run_build') {
}
backend.gradle
buildscript {
ext {
springBootVersion = '1.5.8.RELEASE'
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'org.springframework.boot'
group = 'ch.renewinkler'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
jar {
from('frontend/www') {
into('public')
}
}
processResources.dependsOn(':frontend:build')
dependencies {
compile('org.springframework.boot:spring-boot-starter-web')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
You need to tell gradle that the jar task depends on the frontend's build task, otherwise it could run the jar file before the build task, and thus have nothing to include in the jar.
It's also a better idea to refer to projects by their name, instead of using absolute paths:
jar {
dependsOn(':frontend:build')
into('public') {
from "${project(':frontend').projectDir}/www"
}
}
I have 2 Gradle projects that I want to link together. The first project has a standard Spring Boot app, and I want to link it with a ReactJS project that I've added a "build.gradle" file to.
I want to include the files generated into the "build/" directory of the ReactJS project into the "META-INF/resources" directory of the Spring Boot project.
These are my gradle.build files:
Spring Boot Gradle project:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'org.springframework.boot:spring-boot-gradle-plugin:1.5.2.RELEASE'
}
}
apply plugin: 'java'
apply plugin: 'org.springframework.boot'
group = "com.myproject"
version = "1.0"
bootRun {
systemProperties = System.properties
}
repositories {
jcenter()
}
dependencies {
compile("org.springframework.boot:spring-boot-starter-web")
compile("com.myproject:myproject-ui:1.0")
}
ReactJS Gradle project:
plugins {
id "com.moowork.node" version "1.1.1"
}
node {
download = true
}
apply plugin: 'java'
group = "com.myproject"
version = "1.0"
buildDir = 'dist'
task webjar(type: Jar, dependsOn: 'jar') {
from(fileTree('build')) {
into 'META-INF/resources'
}
}
build.dependsOn(webjar)
build.dependsOn(npm_run_build)
clean {
delete 'dist'
delete 'build'
}
Assume I've setup the "settings.gradle" files correctly such that it is a composite build, because that doesn't seem to cause issues.
When I run the "build" task for the ReactJS project, the "build/" directory is successfully generated, but I doesn't seem to be included by the Spring Boot project anywhere. How can I include the generated HTML/JS files such that they show up when I run the "bootRun" task of the Spring Boot project.
Typically you'd use a Configuration for this
reactjs/build.gradle
configurations {
wj
}
task webjar(type: Jar) { ... }
dependencies {
wj files(webjar)
}
springboot/build.gradle
configurations {
wj
}
dependencies {
wj project(path: ':reactjs', configuration: 'wj')
}
war {
with copySpec {
from zipTree(configurations.wj.singleFile)
into 'META-INF/resources'
}
}
I'm facing some problems with my multimodule project gradle build in IntelliJ. My gradle build works correctly, but IntelliJ is not picking it up as it should causing my development cycle to slow down drastically.
I have this dependency setup between my projects (5 projects, 3 wars, shared has my model etc. common-web has the common web components)
TD (war) -> common-web
CP (war) -> common-web
CP (war) -> Shared
Web (war) -> common-web
Web (war) -> Shared
Shared
common-web
With the following structure:
|- TD
|- Web
|- Shared
|- common-web
|- CP
| settings.gradle
| build.gradle
I have one gradle build file and one gradle settings file.
include 'TD', 'CP', 'Web', 'Shared', 'common-web'
allprojects {
repositories {
mavenCentral()
}
sourceCompatibility = 8
task wrapper(type: Wrapper) {
gradleVersion = '1.11'
}
subprojects {
apply plugin: 'java'
apply plugin: 'idea'
dependencies {
// dependencies...
}
}
project(':CP') {
apply plugin: 'war'
dependencies {
// dependencies...
compile project(':shared')
compile project(':common-web')
}
}
project(':web') {
apply plugin: 'war'
dependencies {
// dependencies...
compile project(':common-web')
compile project(':shared')
}
}
project(':shared') {
dependencies {
// dependencies...
}
}
project(':TD') {
apply plugin: 'war'
dependencies {
// dependencies...
compile project(':common-web')
}
}
project(':common-web') {
apply plugin: 'war' // needed to allow the providedComp
dependencies {
// dependencies...
}
}
Is there a way I should configure the gradle idea plugin to allow this to be build correctly? have found the make button does not work like I think it should work, ignoring the compile errors in the modules etc. I see that in the root of the project, IntelliJ creates a folder classes/artifacts and does not use the (correct) build in the module/lib folder.
The errors I'm seeing is the wrong include of the jars. For example the web project has a dependency to the TD project, which is defined nowhere.
Is this a bug in the gradle plugin of IntelliJ or am I doing something I shouldn't?