Gradle include build - gradle

How include some files (folders) from build directory, after project compile?
I have project with such structure
root
--moduleA
--moduleB
So I want after build all project
moduleA.jar include build directory from moduleA and build directory from moduleB
I found small example https://gist.github.com/marcokrikke/5481001
But it don't work on multi-project builds
Add info
github.com/feedm3/spring-boot-gwt
After compile all GWT filesd exists in
ext.buildDir = "${project.buildDir}/gwt"
ext.extraDir = "${project.buildDir}/extra"
And they must be in jar
This example work fine. But I have problem with multi-project builds

Related

Gradle - paths in multi-project builds

I have a multi-project gradle project with following directory structure:
+ project_root
+ module1
+ src
build.gradle
+ module2
+ src
build.gradle
+ web
..
build.gradle
settings.gradle
In module1/build.gradle among other things I have specified:
compileKotlin2Js.kotlinOptions {
outputFile = "web/script.js"
}
It is a special Kotlin JS setting that specifies output file path of compiled JS file.
Now my problem is, that when I build the whole project (project_root/build.gradle) the file ends up in the right directory (project_root/web), but when I accidentally run build on the module alone the file is saved in module directory (project_root/module1/web).
How can I fix paths in my build scripts, so file output will be saved in exactly the same directory no matter which build script I run (without specifying full path, I want a relative path)?
I don't know what Gradle plugin requires the path parameter in your code example, but all regular (non-3rd-party) Gradle plugins evaluate path parameters via Project.files(Object...) to avoid different locations when calling Gradle from various working directories.
I would suggest to use the above method (or its single file version Project.file(Object)) as well. You can even omit the project part, because the build.gradle file gets executed in the project scope:
compileKotlin2Js.kotlinOptions {
outputFile = file('web/script.js')
}
This will always evaluate the path relative to the project directory of the project your build.gradle belongs to. To evaluate a file relative to the project directory of the root project, use rootProject.files(Object...), for a path relative to the project directory of a subproject or any project in the build, use project(':path:to:project').files(Object...).

compile and build gluon mobile app for desktop

we have
desktopRuntime 'org.xerial:sqlite-jdbc:3.15.1'
in gradle file.
i build project but my zip file dont have this file in lib folder.
how can i build project for desktop?
my ide is netbeans.
Thankful.
The problem with the distZip or jar gradle tasks is they miss to include desktop dependencies.
When deploying to desktop you can change temporary desktopRuntime to runtime, so they will be included, as Ladislav Török suggests, but then you should undo the change so that dependency isn't included in the mobile deployment.
If you want to have a working zip, we have to modify the distZip task, to include the desktop dependencies in the lib folder, and also to include them in the class path (so they are also added to the scripts in the bin folder). Include this in your build.gradle script:
startScripts {
classpath += configurations.desktopRuntime
}
distZip {
into("$project.name/lib") {
from configurations.desktopRuntime
}
}
You can also solve the issue by using the shadowJar, providing you include the desktop dependencies, to create an executable fat jar, like in this solution.
Try next steps:
1.
dependencies {
compile 'org.xerial:sqlite-jdbc:3.15.1'
runtime 'org.xerial:sqlite-jdbc:3.15.1'
}
Go to "Files" tab in NetBeans IDE -> your_project -> build -> libs and here add your lib some as sqlite-jdbc.jar

Referencing an external project from a sub project in gradle

I have a project setup like so where my projects are all in sibling folders relative to one another:
+ mainApp
+ mylib
+ mylib2
mainApp references the mylib library project that is not in its root with the following in my settings.gradle:
include ':app', ':mylib'
project(':mylib').projectDir=new File('..\\mylib')
However, the issue is that the mylib project depends on another lib - mylib2. I can essentially do the same thing and reference mylib2 using settings.gradle and building mylib works fine.
The problem is when I try to build mainApp, it cannot find mylib2 because the settings.gradle of a sub-project is not ran, only the root settings.gradle is ran. So, when the build.gradle file of mylib references mylib2, it cannot find mylib2.
I do not want to add a reference to mylib2 from mainApp, I want mylib2 to be brought in by mylib.
Is there a way to bring in mylib2 from the build.gradle file of mylib ?
It seems like you have a wrong understanding of subprojects.
Every "Project Tree" has a rootProject. This rootProject is the only project that should have a settings.gradle wich includes all subprojects. So if all of your 3 Projects belog together, then they must all be included in the settings.gradle.
References to other foreign project should be added as dependencies. Note that you can only reference Artifacts this way.
You did not make it very clear, but it seems like you want to use the project "mylib" as a Library for the source code of "mainApp"
If those are java projects you can simply add the jar file produced by "mylib" to the compile configuration of "mainApp":
apply plugin: 'java'
dependencies {
compile fileTree(dir:'../myLib/build/libs', include : '**/*.jar')
}
For other languages you have to use the language specific support for that language.

How do I prevent Gradle from building a non-project directory?

In the Gradle samples (included with version 2.2.1) there is a java/multiproject project.
The settings.gradle file defines the following projects:
include "shared", "api", "services:webservice", "services:shared"
Note that services is not itself a project, merely a directory which contains the webservice and shared projects.
When I run the command gradle build from the root directory, I notice that after gradle successfully builds it creates inside the /services directory a /build directory containing /lib and a /tmp directories.
Inside of /services/build/lib is a jar: services-1.0.jar which contains very little; specifically just a META-INF/MANIFEST.MF file containing:
Manifest-Version: 1.0
provider: gradle
So what is causing Gradle to build a jar for this non-project? And how can I prevent this behavior in my similarly structured multiproject project?
/services isn't a project, I don't want to create anything inside /build folder at all. Yes I could just delete it, but I would like to avoid the unnecessary work of building this jar/running any tasks on this non-project in the first place.
To be honest I've no reasonable idea why gradle builds this folder. I guess that because it's a kind of a transient folder. However it can be excluded by adding the following piece of code to main build.gradle script:
project(':services').jar { onlyIf { false } }
Desired effect (services.jar elimination) can be also obtained with the following settings.gradle content:
include "shared", "api", "services/webservice", "services/shared"
File instead of project paths are included.
My guess would be that this is a combination of the next 2 gradle rules:
When you're including subprojects in the build.settings file using the include keyword according to Gradle Documentation here:
the inclusion of the path 'services:hotels:api' will result in
creating 3 projects: 'services', 'services:hotels' and
'services:hotels:api'.
In simple words, this means that the inclusion of services::webservice will also build the services project
The bulid.gradle file in your root that applies the 'java' plugin. According to Gradle Documentation here every configuration defined in the root.gradle takes effect for all sub projects. This means that it will also hold as the default configuration for the services project. As the 'java' plugin was applied a jar will be created, but as there is no src/main folder under the services directory nothing will be compiled and the jar will include only a META-INF/MANIFEST.MF file.

Gradle specify settings dir path for a sub project

In a multi-project build I have a module that in itself is composed of two sub-projects. If I just want the option of building the top-level module but also ensure both the sub-projects within it are also built, how I do achieve this?
include 'moduleA', 'moduleB', 'moduleC' (root project settings.gradle)
project(':moduleC').projectDir = new File('path to custom module that includes sub-projects)
project(':moduleC').settingsDir = ?? (gradle fails because there is no settingsDir path)
but moduleC has a settings.gradle in itself that has
include 'api'
include 'server'
Now I want both these to be triggered when I specify gradlew :moduleC:build, but instead it just builds moduleC root project. Is there a way? This use case does seem valid to me (i.e. for modularity, you want to keep the inclusion of sub-projects at moduleC's level and not at root level).
Thanks,
Paddy
As of Gradle 2.2, only a single settings.gradle per build is supported. If that file contains include "moduleC:api" and include "moduleC:server", then running gradle build from moduleC's project directory will also build api and server.

Resources