'Java Intellij: Make change on external lib code and take effect immediately
I am working on Java with Intellij. Now I can debug into my external lib code by attaching source to jar lib. But now I want to make change on lib's source code and make it take effect immediately without repackaging to jar and including again to my main project. Can I do that ?
Solution 1:[1]
If you have source code for the library, create a separate module with this source code and add a dependency on that module instead of a library jar.
And to have a jar library synchronized with the source code, you can configure the jar artifact to be built from this library module together with the project build.
Solution 2:[2]
For the other answers that are saying this isn't good practice, I agree but sometimes it can be useful. For example when I wanted to test a change in an external jar before submitting a merge request against the library with the suggested change. It was useful to be able to test it locally.
What I did was
- Clone the library locally
- Change the version in the pom.xml to something different e.g.
testing-snapshot - Run
mvn clean installin the new cloned project to load the project into your local m2 folder - In the your main pom.xml where you want your new version of the project to take affect, change the version to what you chose in step 2.
- Now reload all maven project and intellij should pick up this new version which you can now edit the source code
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Andrey |
| Solution 2 | Metin Dagcilar |
