Change working directory for gradle multi-module project - java

I'm a new Gradle user coming from Maven and I've hit a bit of a roadblock in our CI builds due to the issue with the working directory in a multi-module build. Specifically it's the unit tests, as I have a few unit tests that are loading resources that are relative to the sub-project directory.
If I build the projects individually, everything works as expected. If I build them using the master build.gradle file, then I run into issues with files not being found, etc.
So the question is,can I change the working directory when gradle forks a new Java process to build the sub-module?
TIA

I've the similar problem: shared config directory in root for Gradle muli-module, migrated from Maven. Manipulation with projectDir (https://discuss.gradle.org/t/how-do-i-set-a-common-build-directory-for-multi-module-builds-in-the-root-project-directory/5570, https://docs.gradle.org/current/userguide/fine_tuning_project_layout.html#sub:modifying_element_of_the_project_tree) is restricted in last Gradle version, so I've moved to defining root directory location environment variable or fixed place (e.g. ~ or \..\..) or JVM parameter with this location.

Related

Generate Eclipse launch configurations with Gradle

We use Eclipse to launch and debug our Java GWT project. We have a couple of eclipse launch configuration files with many classpath entries needed for running the project.
Previously we used ant to build our project and had all our dependencies present on our local storage, with all classpaths pointing to libraries explicitly for project as well as launch configuration classpaths.
Once we migrated over to Gradle 6.6 and used public repositories to download our dependencies, almost everything worked smoothly - all our project classpaths were generated correctly by the gradle build. However, our eclipse launch configurations still contain the old hardcoded classpaths and I'm unable to find a way to generate these launch configurations using those gradle configured classpaths. As a result we've had to maintain the dependencies on our local filesystem so that the configurations have access to them in order to debug and run our code.
Is there a way Gradle can be used to generate these launch configurations so that we can get rid of the libraries on our filesystem and rely on whatever it pulls from the repositories during a build?
Any suggestions or workarounds will be appreciated.
It you're using Eclipse's built-in Gradle tooling (aka, Buildship) and let Eclipse generate your launch configuration, it will automatically be in sync with the project's build path, which is automatically kept in sync with the dependencies declared in your Gradle build file.
Here is an example Gradle project I just created, where I added some dependencies and the launch configuration "just works." The project is named "lib," notice under Classpath Entries is "Project Dependencies"; that's where Eclipse's Gradle tooling maintains and syncs with what's in the build.gradle file.
Here's what the project's Build Path looks like if I inspect it:
Whenever you add a dependency to build.gradle, it will automatically be included there; the launch configuration(s) then reference the project dependencies so the launches are also always in sync.
You might need to delete your existing launch configurations and let Eclipse generate new ones to get this.

How to reference other classesdir in Gradle multi-project build

I am building an API using spring boot. I'm using gradle and a multi-project build set up where I have a services-lib project and an api project that depends on the services-lib.
Running the api:bootRun tasks in the api project works perfectly fine, but now I'm trying to add the ability to trigger an spring-boot-devtools automatic restart, which requires the bootRun task to have the service-lib classdir in it's classpath(not the jar that is added by the multi-project dependency).
Adding this to my api's build.gradle does trigger the automatic restart when I run the api:build task (where "C:/foo/bar" is the absolute path to my multi-project root directory).
bootRun {
classpath += files('C:/foo/bar/services-lib/build/classes/java/main')
}
My question is, instead of having to hard code that path, can I set it using something like project(':services-lib')?
Well I did figure this out thanks to Kidus' suggestion.
bootRun {
bootRun.systemProperty 'spring.profiles.active', 'dev'
classpath += files('../services-lib/build/classes/java/main')
}
It still means if I change anything about the build output in the services-lib project I have to change it hear but at least now when others check out the project now it will work for them.

JavaFX: Maven Plugin - Make the executable file reference to a maven repo instead of the lib folder

I'm looking for a way to create an executable jar file for my JavaFX application.
I'm currently using the zenjava maven plugin and I use the jfx:jar goal. Doing this, all the dependencies are generated on a folder called /lib.
The problem arises when one of the dependencies (a separate project handled by another group) is updated, I would need to rebuild my jar again.
Is it possible to just maybe refer to the dependencies using a pom? (not point to the lib) So I would only update the pom every time a dependency is updated?
Thanks in advance!
Short answer: nope, not possible
Long answer: the JavaFX-Maven-Plugin is usable for development (via mvn jfx:run) and deployment (via mvn jfx:jar or mvn jfx:native).
You are generating a potential deployable package, which already contains everything needed to execute on some targeted machine. You would have to encapsulate your javafx-application with a "pre-loader" which downloads all your required stuff to be executable.
What is the idea behind distributing an application which needs some internet-connection to gather all the required dependencies?
Disclaimer: I'm the maintainer of the javafx-maven-plugin.

Intellij Idea compiler recompiles already compiled project

I use maven command which cleans,builds whole project, creates war and deploys to server. I cannot use Intellij to do that since I have only Community edition. It builds the project in same directory as intellij.
To speed things up I wrote a script which finds compiled files in local "target" directory which are newer than the ones in server and copy them. It all works okay but the problem is Intellij does not see classes compiled with maven as the ones it should skip and rebuilds whole project all over.
Currently it works like this:
Manually in terminal build whole project with maven
Go back to intellij -> make project
Rebuilds all
Run script -> it swaps all files
What I am trying to achieve:
Manually in termin build whole project with maven
Go back to intellij. Change one file -> make project
Compiles only one java file
Run script -> it swaps only one .class file
So the problem is how do I make intellij treat files already compiled with external tool as compiled?
You don't. IntelliJ IDEA has its own incremental compilation system which tracks the dependencies between files being compiled and recompiles the minimum set of classes for every set of changes. External compilation with tools like Maven or Gradle does not update IntelliJ IDEA's incremental compilation database. Because of that, IntelliJ IDEA cannot recognize the fact that classes have been already compiled with an external tool, and will recompile.
That troubled me for long time. Finally, i found this .
IDEA build settings
You can choose whether use InteliJ or gradle to compile when runnning program. Under gradle project, it uses gradle to build by default.

Resolving dependencies in Eclipse for Fitnesse

My goal is to run unit tests in fitnesse.responders.run.slimResponder for testing my DataFlex SlimRunner implementation. So I downloaded the Fitnesse source code, and made it a new Java project in Eclipse. I was able to compile it by selecting Run As Ant Build (2) on the build.xml file. But in order to resolve include errors in the Problems view in Eclipse, I ended up manually adding dozens of external JARs by hand. I found that Maven/Ivy had apparently downloaded the jars as part of the Ant build. But somehow these were not added to the Java Build Path.
It seems reasonable to me to assume that there should be an easier way to set up the Java Build Path than to add the JAR files manually, since build.xml apparently contains all this information already. What am I missing?
The Fitnesse Readme.md mentions using Apache Ivy for dependency management. Download IvyDE from Eclipse Marketplace, and set it up (use the ivy.xml that is part of the Fitnesse source code).

Categories

Resources