So I have an intellij IDEA project (project A) which includes a bunch of external jar libraries. I am currently working on one of those external jar libraries (project B) and I want to replace it with the local project (project B) on my computer.
So, in short: I have Project A which depends on jar B I want to replace jar B with my local project (project B)
That way, when I run project A, it uses Project B local rather than Jar B external. Anyone know any good easy ways of doing this?
Your use case is exactly what composite builds in Gradle are made for. The docs even mention your precise use case:
Composite builds allow you to […] combine builds that are usually developed independently, for instance when trying out a bug fix in a library that your application uses
A composite build allows you to temporarily and easily replace an external dependency library with a locally available build project of that library. (It would even work with multiple different dependencies.)
Here’s how you’d set this up for your two projects (leaving out Gradle Wrapper files and Java source code for conciseness):
├── projectA
│ ├── build.gradle
│ └── settings.gradle
└── projectB
├── build.gradle
└── settings.gradle
Note that the two project directories don’t actually have to be siblings. I’ve only done that here to keep it simple. In my minimal sample build, the two settings.gradle
files can be empty. The two build scripts look as follows.
projectA/build.gradle
plugins {
id 'java'
}
dependencies {
implementation 'com.example:projectB:1.2.+'
}
repositories {
// where you get the projectB dependency from normally
}
projectB/build.gradle
plugins {
id 'java-library'
}
group = 'com.example'
version = '1.2.3'
Under projectA/
, simply run ./gradlew --include-build ../projectB build
(or any other Gradle task(s) you’re interested in). Make sure to use the right path to the directory of projectB. The --include-build
option automatically creates the composite build on-the-fly.
You can also create a composite build in IntelliJ. To do that:
build.gradle
file to make sure that IntelliJ automatically uses the Gradle configuration).build.gradle
file of projectB.That’s it. You should now be able to use projectA with its locally available dependency projectB.