Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

251
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda