Add multi project itself as a dependency in another project - java

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.

Related

ObjectBox build.gradle

Trying out to use ObjectBox as java desktop database. However after following the documentation on the web site https://docs.objectbox.io/java-desktop-apps its not working. No MyObjectBox found error.
I am using eclipse ide Version: 2020-09 (4.17.0), Gradle: gradle-6.7.1
ObjectBox seems not creating the model automatically after build (no model folder generated). I have created the class using the Entity annotation, build the project eclipse, nothing happens. Anyone any ideas?
Works in android but not desktop. As i am not familiar with gradle project in eclipse. the following is the build file
buildscript {
ext.objectboxVersion = '2.8.1'
repositories {
jcenter()
}
dependencies {
classpath "io.objectbox:objectbox-gradle-plugin:$objectboxVersion"
}
}
apply plugin: 'java-library'
apply plugin: 'io.objectbox'
targetCompatibility = '1.8'
sourceCompatibility = '1.8'
repositories {
jcenter()
}
dependencies {
implementation "io.objectbox:objectbox-linux:$objectboxVersion"
implementation "io.objectbox:objectbox-macos:$objectboxVersion"
implementation "io.objectbox:objectbox-windows:$objectboxVersion"
}
apply plugin: 'io.objectbox'
dependencies {
implementation "io.objectbox:objectbox-java:$objectboxVersion"
annotationProcessor "io.objectbox:objectbox-processor:$objectboxVersion"
}
apply plugin: 'io.objectbox'
Doing apply plugin: 'io.objectbox' three times does not look good. Once is enough. Please check the ObjectBox Java examples for a working setup. In your case have a closer look at the java-main example for standalone Java applications.
This is the basic structure with ... where I left out the details (check the full build.gradle file from the example):
buildscript {
...
}
apply plugin: 'java'
apply plugin: 'application'
targetCompatibility = '1.8'
sourceCompatibility = '1.8'
mainClassName = "io.objectbox.example.Main"
dependencies {
...
}
// Apply plugin after dependencies block so they are not overwritten.
apply plugin: 'io.objectbox'
Maybe checkout the example and start from there?

Gradle loaded Serenity libs to project libraries but can't see them further

I have this build.gradle file
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'net.serenity-bdd.aggregator'
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
jcenter()
}
buildscript {
repositories {
mavenLocal()
jcenter()
}
dependencies {
classpath("net.serenity-bdd:serenity-gradle-plugin:1.4.0")
}
}
dependencies {
testCompile('net.serenity-bdd:serenity-core:1.4.0')
testCompile('net.serenity-bdd:serenity-junit:1.4.0')
testCompile('junit:junit:4.12')
testCompile('org.assertj:assertj-core:1.7.0')
testCompile('org.slf4j:slf4j-simple:1.7.7')
}
gradle.startParameter.continueOnFailure = true
It loads serenity libraries to the project BUT some classes are not visible when compile:
PageObject class is not visible
but it truly exists in External libs:
Class in the libs
What should I do to make it be visible in test classes and page object classes?
Also when I import manually by entering full path to the library then gradle runner does not see those classes anyway.
Issue is resolved. Wrong compile scope was chosen. Need to be compile not testCompile.

kotlin project can't be build in gradle

I have a java project that write in kotlin ,i use intelliJ IDEA to develop this project. I have trouble on the dependencies setting (multiple project). I already read lot of examples , but I can't find the workaround , here is my dependencies setting code,
it can be build in java class correctly , but the kotlin class will get lot of error 'Unresolved reference' . Is that any wrong about my setting or gradle is not suitable with kotlin .
PS : when i only build core project , build process will successful , but build at test project will get the reference unresolved error
allprojects {
apply plugin: 'java'
apply plugin: 'kotlin'
group 'testProject'
version '1.0'
}
subprojects{
apply plugin: 'java'
apply plugin: 'kotlin'
def defaultEncoding = 'UTF-8'
compileJava.options.encoding = defaultEncoding
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
mavenLocal()
}
dependencies {
// Kotlin
compile "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
}
}
project(':test') {
dependencies {
compile project(':core')
compile project(':testTwo')
}
project(':testTwo'){
dependencies{
compile project(':core')
}
setting.gradle
include 'test','testTwo','core'
The kotlin-gradle-plugin is not a dependency of your subprojects, it is a dependency of the buildscript itself.
Follow the instructions on Plugin and Versions

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