I need to setup a Gradle multiproject java build with a fixed build folder.
The structure needs to be like this:
--projectRoot/
----build/ (shared for both subprojects)
----javaApp1/
----javaApp2/
After the build there should be two shell scripts for starting the applications:
--projectRoot/
----build/
------javaApp1
------javaApp2
------libs/
--------javaApp1.jar
--------javaApp2.jar
so far my settings.gradle is in the projectRoot:
rootProject.name = 'com.example.project'
include 'javaApp1'
include 'javaApp2'
and the build.gradle in the projectRoot:
allprojects {
repositories {
jcenter()
}
buildDir = new File(projectDir, "../build")
}
subprojects {
group 'com.example.project'
apply plugin: 'java'
apply plugin: 'application'
dependencies {
testImplementation 'junit:junit:4.12'
}
}
with this I'm already able to build from the projectRoot and with gradle installDist I get the wanted shell scripts in projectRoot/build/install/javaApp1/bin/javaApp1 but not in the build folder directly.
So to recap: the shell scripts should end up in projectRoot/build.
Related
I converted a project to gradle using gradle init from maven after updating the dependencies. gradle test works as expected. However, when I run gradle build, the jar file that's generated is entirely empty.
I've attempted to tweak the source set to make something happen, but that doesn't seem to solve the problem. The directory structure matches what gradle expects from what I can tell everything is nested in src/main/groovy
The project's full code is available on Github.
In general what causes no files to be added to a build? Is there additional configuration I need to add besides whatever gradle init creates?
Gradle build file:
plugins {
id 'java'
id 'maven-publish'
}
repositories {
mavenLocal()
mavenCentral()
jcenter()
}
dependencies {
implementation 'org.codehaus.groovy:groovy-all:3.0.5'
implementation 'com.github.javafaker:javafaker:1.0.2'
testImplementation 'org.spockframework:spock-core:2.0-M3-groovy-3.0'
testCompileOnly 'org.projectlombok:lombok:1.18.12'
testAnnotationProcessor 'org.projectlombok:lombok:1.18.12'
}
group = 'nl.topicus.overheid'
version = '0.2.0'
description = 'java-factory-bot'
sourceCompatibility = '1.8'
publishing {
publications {
maven(MavenPublication) {
from(components.java)
}
}
}
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
What going on now is the project is try to build as Java project and get src from src/main/java as it is default from Java project. So, you need id 'groovy' not id 'java' in plugins section to make it look into src/main/groovy and build both .java and .groovy files in there.
I am using IntelliJ and gradle to create a multi-module spring project as shown below.
With the following build.gradle in the root folder, I have the following settings below. When invoked gradle build, a jar gets created in build/libs, however executing that jar I get the error message:
**Error: Could not find or load main class com.connect.configuration.ConnectApplication
** When running the application without building via: gradle bootRun -- the application loads up correctly. However, executing the jar file after building the project, produces the error and the jar prints out the following: using
jar -tf myJar.jar
META-INF/
META-INF/MANIFEST.MF
plugins {
id 'io.spring.dependency-management' version '1.0.8.RELEASE'
id 'java'
}
subprojects {
group = 'com.connect.connect'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.9
targetCompatibility = 1.9
apply plugin: 'java'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'java-library'
repositories {
jcenter()
}
dependencies {
compileOnly 'org.projectlombok:lombok:1.18.10'
annotationProcessor 'org.projectlombok:lombok:1.18.10'
}
dependencyManagement {
imports {
mavenBom("org.springframework.boot:spring-boot-dependencies:2.1.9.RELEASE")
}
}
}
settings.gradle
include 'connect-common'
include 'connect-ui'
include 'connect-services'
include 'connect-application'
include 'connect-configuration'
I recently started using Gradle but i'm having an issue compiling my application.
This is my build.gradle:
group 'net.zentya'
version '1.0-SNAPSHOT'
apply plugin: 'groovy'
apply plugin: 'java'
repositories {
mavenCentral()
maven { url "https://hub.spigotmc.org/nexus/content/repositories/snapshots/" }
maven { url "https://oss.sonatype.org/content/groups/public" }
}
dependencies {
compile 'org.codehaus.groovy:groovy-all:2.3.11'
compile 'org.spigotmc:spigot-api:1.11.2-R0.1-SNAPSHOT'
compile 'org.bukkit:bukkit:1.11.2-R0.1-SNAPSHOT'
compile 'net.md-5:bungeecord-chat:1.11-SNAPSHOT'
}
sourceSets {
main {
java {
srcDir 'src'
}
}
}
When building with the IntelliJ's pre-made button i get my project compiled's class files into the path {project}/gradle/classes/main . But i don't have the final JAR.
How i can fix?
gradle jar or gradle shadowJar commands can be used to create the jar file of gradle based applications.
We are starting a new Project with gradle (all of my previous projects are on Maven) and this is my first experience on using gradle, below is my build.gradle file and am trying to compile the java and groovy sources using the task compile
buildscript {
ext {
springBootVersion = '1.5.2.RELEASE'
springVersion = '4.3.7.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'groovy'
apply plugin: 'org.springframework.boot'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
task compile(type: GroovyCompile) {
//source = fileTree(dir: 'src', include: '**/*.java')
sourceSets {
main {
java { srcDirs = [] } // no source dirs for the java compiler
groovy { srcDir "src" } // compile everything in src/ with groovy
}
}
destinationDir = file('build/classes/main')
classpath = files('build/classes/main')
}
dependencies {
compile "org.codehaus.groovy:groovy-all:2.4.10"
compile('org.springframework.boot:spring-boot-starter-actuator:${springBootVersion}')
compile('org.springframework.boot:spring-boot-actuator-docs:${springBootVersion}')
compile('org.springframework.boot:spring-boot-starter-groovy-templates:${springBootVersion}')
compile('org.springframework.boot:spring-boot-starter-jdbc:${springBootVersion}')
compile('org.springframework.boot:spring-boot-starter-jersey:${springBootVersion}')
compile('org.springframework.boot:spring-boot-starter-security:${springBootVersion}')
compile('org.springframework.boot:spring-boot-starter-web:${springBootVersion}')
compile('org.springframework:spring-webmvc:${springVersion}')
compile "com.microsoft:sqljdbc4:4.0"
testCompile('org.springframework.boot:spring-boot-starter-test:${springBootVersion}')
}
And when I run the gradle compile command am seeing :compile NO-SOURCE and no compiled classes in build\classes\main
can someone please help me with gradle task to compile both java and groovy sources?
The Gradle docs of the Groovy plugin describe the default layout like follows. If it is an option to stick to that, there is no need for a custom compile task.
src/main/java Production Java source
src/main/resources Production resources
src/main/groovy Production Groovy sources. May also contain Java sources for joint compilation.
src/test/java Test Java source
src/test/resources Test resources
src/test/groovy Test Groovy sources. May also contain Java sources for joint compilation.
```
I followed this tutorial. This runs fine.
I would like to create a multiproject build with one project that contains this spring application. So I added this project to a subfolder called web of this multiproject build, added a settings.gradle file:
include 'web'
As well as a build.gradle file:
apply plugin: 'application'
mainClassName = "hello.Application"
jar {
baseName = 'VoPro'
}
dependencies {
compile project(':web')
}
However, when i run $ gradle build, i get the error:
Could not resolve all dependencies for configuration ':runtime'.
> Cannot resolve external dependency org.springframework.boot:spring-boot-starter-web: because no repositories are defined.
Required by:
:test:unspecified > test:web:unspecified
Why can't gradle find any repositories?
EDIT: The web subproject contains the following build.gradle file (like in the tutorial):
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.2.2.RELEASE")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'spring-boot'
jar {
baseName = 'gs-rest-service'
version = '0.1.0'
}
repositories {
mavenCentral()
}
dependencies {
compile("org.springframework.boot:spring-boot-starter-web")
testCompile("junit:junit")
}
task wrapper(type: Wrapper) {
gradleVersion = '1.11'
}
You should add a build.gradle file under the web project itself and configure appropriate repositories there. Or add a global build.gradle and the following piece of code in it:
allprojects {
repositories {
mavenCentral()
mavenLocal()
}
}
Basically the multimodule project should have the following structure
-- build.gradle // all projects configuration
-- settings.gradle //includes all modules
-- module1
-- build.gradle
-- module2
-- build.gradle
-- modulen
-- build.gradle
..
After discussion in comments:
You need to specify the dependency along with version, no idea why:
compile("org.springframework.boot:spring-boot-starter-web:1.2.2.RELEASE")