Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

250
Views
Replace external jar dependency with local intellij project

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?

over 4 years ago · Santiago Trujillo
4 answers
Answer question

0

Solution with gradle:

In Project A build.gradle add mavenLocal() to the repositories.

...
repositories {
  mavenLocal()
  maven { url ... }
}
...

In Project B you need the maven-publish plugin, and the related task.

plugins {
  id 'maven-publish'
}

sourceSets {
  main {
    java {
      srcDir 'src/main/java'
    }
  }
}

task sourcesJar(type: Jar) {
  from sourceSets.main.allJava
  classifier = 'sources'
}

publishing {
  publications {
    mavenJava(MavenPublication) {
      artifactId = rootProject.name //or some string eg.: 'projectb'
      groupId = project.group //or some string eg.: 'com.example'
      version = project.version //or some string eg.: '1.0.3.9'
      from components.java
      artifact sourcesJar
    }
  }
}

Now you can run the publishToMavenLocal task from your terminal, or from Gradle View in IntelliJ. (It is on the right side by default, gradle tab, expand your project and bellow publishing you can find the task.)

over 4 years ago · Santiago Trujillo Report

0

Using Composite Builds

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

Complete Example

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'

Running the Sample

On the Command Line

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.

In IntelliJ IDEA

You can also create a composite build in IntelliJ. To do that:

  1. Import projectA as usual (via its build.gradle file to make sure that IntelliJ automatically uses the Gradle configuration).
  2. In the Gradle tool window, you click the + button (“Link Gradle Project”) and select the build.gradle file of projectB.
  3. Right click projectA in the Gradle tool window and select “Composite Build Configuration”. In the opening dialog, select projectB and click “OK”.
  4. In the Gradle tool window, click the 🗘 button (“Reload All Gradle Projects”).

That’s it. You should now be able to use projectA with its locally available dependency projectB.

over 4 years ago · Santiago Trujillo Report

0

Since you have the tag "gradle", I'm assuming you are using it for both projects. Run "gradle publishToMavenLocal" in project B and then refresh the dependencies of project A.

Just make sure you remember you did this and delete project B from your local repository when you are done with it.

over 4 years ago · Santiago Trujillo Report

0

  1. Open module A in IntelliJ IDEA;
  2. Go to File-> Project Structure -> Modules -> module A -> Dependencies (Tab) -> find and delete B.jar (there is "-" button for that);
  3. Next click "+" button and add folder which contains compiled classes of your local module B.
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!