Changing files from an external library in Java

I have a Spring Framework project that uses Maven to resolve dependencies. The project has a dependency on another Spring project (Spring Social Facebook), which is used to log into Facebook. Suddenly, I got a lot of errors because the Facebook login feature was broken due to changes in the Facebook API. The solution is very simple, but requires minor changes in the external library files - changing the variable from an integer to long.

Now I know the solution, but I have no control over this library. I would like to solve this problem myself, until the library is updated with a fix, and waits for several days with a broken system.

My question is: is there any simple way by which I can make changes to the source code of this library until the fix is ​​available in the library itself? What is the recommended way to do this? Two things currently come to mind: formatting the library, making changes, and creating a private Maven repository and replacing the dependency with the one that uses the private repository. If I can, I would like to avoid it. Another way I can think of is to develop a library, make changes, compile the updated library into a jar file, and replace the Maven dependency with a jar file.

Is there a better way? What would you recommend in a (temporary) scenario like this? Thanks!

+4
source share
2 answers

From experience in several companies, I saw the following approach:

  • Fix the problem in the source code
  • Packet again with the same Maven coordinates
  • Add a classifier, which was usually the company name-patch (ed)
  • Put it in the Maven corporate repository (i.e. Artifactory or Nexus)

So you go from

<dependency>
  <groupId>junit</groupId>
  <artifactId>junit</artifactId>
  <version>4.7</version>
</dependency>

To

<dependency>
  <groupId>junit</groupId>
  <artifactId>junit</artifactId>
  <version>4.7</version>
  <classifier>company-patch</classifier>
</dependency>

This will help you maintain more traceability:

  • The classifier makes it clear to internal developers, as well as contractors, that this is a patch for the company.
  • You know exactly which library and which version the patch was applied to (therefore, partially self-documenting)

Also, this is actually a legitimate and good use of the Maven function classifier.

Maven ( , ?) ( , ops.. , ), Maven ( ?) ( , ops.. ).

+2

Spring Facebook August:

<dependency>
  <groupId>org.springframework.social</groupId>
  <artifactId>spring-social-facebook</artifactId>
  <version>2.0.2.RELEASE</version>
</dependency>

API , , API .

, Facebook, Facebook ( ) API. .., .

, , . , . , , lib, "", Facebook, ​​.

0

Source: https://habr.com/ru/post/1618810/


All Articles