Gradle - multi project compiles but shared project classes not found - java

We are trying to setup a multi project build.
We have 2 projects:
1) PlayerManager
2) Shared
our project compiles and all the tests succeed when we run the gradle.test task
Problem is when we try to run the project on the tomcat from whithin eclipse we get class not found error for all the files in the Shared project.
Here is our gradle.build files:
PlayerManager (root)
=======================
apply plugin: 'war'
apply plugin: 'jetty'
apply plugin: 'eclipse-wtp'
apply plugin: 'eclipse'
apply from: 'dependencies.gradle'
apply from: 'xmlHandler.gradle'
apply plugin: 'base'
dependsOn(":NGShared:NGShared")
task wrapper(type: Wrapper) {
gradleVersion = '1.9'
}
repositories {
mavenCentral()
}
dependencies {
providedCompile 'javax.servlet:servlet-api:2.5'
compile 'org.springframework:spring-webmvc:3.2.2.RELEASE'
runtime 'javax.servlet:jstl:1.1.2'
}
/* Change context path (base url). otherwise defaults to name of project */
jettyRunWar.contextPath = ''
task cleanAndBuild(dependsOn: ['clean', 'assemble'])
assemble.mustRunAfter clean
tasks.withType(Test) {
testLogging {
events 'passed'
}
}
task testSanity(type: Test, dependsOn: testClasses) {
exclude '*/TimeBaseTest*'
}
Shared(sub project)
=======================
apply plugin: 'java'
apply plugin: 'eclipse'
apply from: 'dependencies.gradle'
task wrapper(type: Wrapper) {
gradleVersion = '1.9'
}
settings.gradle
include ":NGShared:NGShared"
======================================================
Our path for the project is:
/NGPlayerManager/
/NGPlayerManager/NGShared/NGShared
Any ideas why ?
Thanks

Have you tried to run 'gradle eclipseClean' and then 'gradle eclipse' in order for gradle to regenerate all internal eclipse config files? If you don't do this, Eclipse will not automatically regenerate its configuration and will not include your child projects into the .ear or .war package

Related

Add multi project itself as a dependency in another project

After a lot of searching, it was the last option to raise it here! In eclipse, I am designing such project structure using Gradle, as shown below...
Algorithms //Parent Project
-SubModuleCore //Child Project for common utilities & dependencies
-build.gradle
-SubModuleOne //Child project for any operation
-build.gradle //Added 'SubModuleCore' as a dependency like compile project(':SubModuleCore')
-SubModuleTwo //Child project for another operation
-build.gradle //Added 'SubModuleCore' as a dependency like compile project(':SubModuleCore')
-build.gradle
-settings.gradle
Services //Stand-Alone project
-build.gradle //Here I want to add 'Algorithms' as a single dependency
-settings.gradle
Project structures are same in eclipse work-space as shown above. I am able to generate individual .jar of Algorithms project. So the problem is I want to add this Algorithms project as a single dependency in project Services like compile project(':Algorithms'). But eclipse just saying 'shut-up!'. I don't want to publish it somewhere like maven central / jitpack etc. instead I want to do it locally. I'm trying this way...
Services/build.gradle
apply plugin: 'war'
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'eclipse-wtp'
project.webAppDirName = 'WebContent'
repositories {
jcenter()
mavenCentral()
}
dependencies {
compile fileTree(dir: 'lib', include: ['*.jar'])
compile project(':Algorithms')
}
Services/settings.gradle
rootProject.name = 'Services'
include 'Algorithms'
project(':Algorithms').projectDir = new File(settingsDir, '../Algorithms')
Algorithms/build.gradle
apply plugin: 'java'
apply plugin: 'eclipse'
sourceCompatibility = "1.8";
targetCompatibility = "1.8";
subprojects {
apply plugin: 'java'
apply plugin: 'eclipse'
sourceCompatibility = "1.8";
targetCompatibility = "1.8";
buildscript {
dependencies {
repositories {
jcenter()
mavenCentral()
}
}
}
repositories {
jcenter()
mavenCentral()
}
}
subprojects.each { subproject ->
evaluationDependsOn(subproject.path)
}
jar.dependsOn subprojects.tasks['classes']
jar {
baseName = 'algorithms'
subprojects.each { subproject ->
from subproject.sourceSets.main.output.classesDir
}
from files('resources/log4j2.xml')
from files('resources/application.properties')
}
Algorithms/settings.gradle
rootProject.name = 'Algorithms'
include ':SubModuleCore', ':SubModuleOne', ':SubModuleTwo'
I tried several solutions from SO, still not succeeded. Somebody please help me, I got stuck badly here. It seems I am very close to this, but don't know what is missing!
Thanks
You can use the includeBuild feature.
Declare the included build in Services/settings.gradle
rootProject.name='Services'
includeBuild '../Algorithms'
and then express the dependency using
compile "${project.group}:${project.name}"
where project group and name the one from the Algorithms project.

How to use DexGuard in java project whith Gradle

I am trying to use DexGuard plugin in Java project whith Gradle. It is library project for android.
But i want to link DexGuard library whitout:
apply plugin: 'com.android.application'
Because I need to use:
apply plugin: 'java'
Is it possible to use DexGuard plugin such a way?
I need this way to use because i need to use an additional plugin:
apply plugin: 'com.github.johnrengelman.shadow'
And I have a problem to use this plugin in conjunction whith android plugin...
My gradle:
buildscript {
repositories {
jcenter()
flatDir dirs: 'DexGuard/lib'
}
}
dependencies {
classpath 'com.github.jengelman.gradle.plugins:shadow:1.2.2'
classpath ':dexguard'
}
}
apply plugin: 'java'
apply plugin: 'com.github.johnrengelman.shadow'
repositories {
mavenCentral()
}
dependencies {
compile fileTree(dir: 'libs', include: '**/*.jar')
}
sourceSets {
main {
java.srcDirs = ['src']
}
}
shadowJar {
...
}
task sdkDexguard(type: com.saikoa.dexguard.gradle.DexGuardTask) {
configuration 'dexguard.txt'
injars 'build/classes'
injars 'libs'
outjars 'build/application.apk'
}
I can not to build tasklist. Error in line task sdkDexguard:
Could not find property 'com' on root project
UPD
Problem in the library DexGuard 6.1.11 for standalone usage. GuardSquare team will solve that soon.
Problem solved in version 7.0.31. Now possible to use this method for standalone usage.

Gradle build successful, error running jar

I am new to gradle.
I am building a project using gradle.
It build successfully without any error. While running the build jar file it is giving classNotFoundException.
I am building a simple spring project from spring.io
However question look similar to this but, could not find a solution. Please help.
edit: This is how my build.gradle looks
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.2.5.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()
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencies {
compile("org.springframework.boot:spring-boot-starter-web")
testCompile("junit:junit")
}
task wrapper(type: Wrapper) {
gradleVersion = '2.3'
}
startScripts {
mainClassName = 'Application'
}
springBoot {
mainClass = "Application"
}
You'll need to start the application with the generated start scripts. They will automatically take care of setting up the proper classpath.

Can gradle include only specific package and exclude everything else

From my project I'm building two jars, one a fat jar for server and the other a thin jar for client. Is there a way to NOT specify all the excludes and make the include mutually exclude everything else (the dependencies as well)
apply plugin: 'java'
apply plugin: 'spring-boot'
apply plugin: 'eclipse'
repositories { jcenter() }
configurations {
compile.exclude module: "spring-boot-starter-tomcat"
}
dependencies {
compile(bootweb)
compile(bootundertow)
testCompile(boottest)
}
mainClassName = 'mordeth.sentinel.util.SentinelServer'
jar{
baseName='sentinel-service-boot'
version = version
}
task clientJar(type: Jar){
baseName='sentinel-service-client'
version = version
from sourceSets.main.output.classesDir
include 'mordeth/sentinel/dto/*.class'
}
artifacts{
archives jar, clientJar
}
apply plugin: 'spring-boot'
apply plugin: 'java'
apply plugin: 'eclipse'
repositories { jcenter() }
configurations {
compile.exclude module: "spring-boot-starter-tomcat"
}
dependencies {
compile(bootweb)
compile(bootundertow)
testCompile(boottest)
}
mainClassName = 'mordeth.sentinel.util.SentinelServer'
jar {
baseName='sentinel-service-boot'
version = version
}
task clientJar(type: Jar, dependsOn: jar){
baseName = 'sentinel-service-client'
from sourceSets.main.output.classesDir
include 'mordeth/sentinel/dto/*'
}
bootRepackage.withJarTask = jar
artifacts{
archives jar, clientJar
}
include method in gradle is by definition mutually exclusive i.e it'll exclude everything not otherwise specified in the include. To avoid spring-boot dependencies getting added to the client jar, one can simply restrict the bootRePackage to a specific (in this case the default) jar task
bootRepackage.withJarTask = jar

gradle: migrate spring app to a multiproject build

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")

Categories