How to exclude library dependencies with explicit url from pom created?

I am moving the Scala Migration project from ant / ivy to sbt. It does not necessarily use log4jdbc as a library dependency that does not exist in any Maven public repository (from what I can find).

libraryDependencies += "log4jdbc" % "log4jdbc" % "1.1" from "http://log4jdbc.googlecode.com/files/log4jdbc4-1.1.jar" 

I want the generated POM not to include log4jdbc since it is not in any repository. Is this the correct assumption that POM would be better without listing log4jdbc? Also, wouldn't it work better for Scala Migrating users with sbt?

I wrote the following parameter to remove the log4jdbc dependency on the POM. Is there a better, easier way? Is it possible to add a parameter to sbt for this automatically?

 // Do not include log4jdbc as a dependency. pomPostProcess := { (node: scala.xml.Node) => val rewriteRule = new scala.xml.transform.RewriteRule { override def transform(n: scala.xml.Node): scala.xml.NodeSeq = { val name = n.nameToString(new StringBuilder).toString if (name == "dependency") { if ((n \ "groupId").text == "log4jdbc") scala.xml.NodeSeq.Empty else n } else { n } } } val transformer = new scala.xml.transform.RuleTransformer(rewriteRule) transformer.transform(node)(0) } 
+4
source share
1 answer

Since you mention POM, I assume that you want to support Maven users or want to publish them to the Maven repository. If this is not the case, you do not need to publish to the POM, and you can simply work with Ivy metadata, for example, in the Ant / Ivy setup.

Since you know Ivy, the from(URL) method from(URL) is essentially implemented by declaring a custom artifact with its from property set to the URL. Regardless of Maven / POMs, Ivy does not include custom artifacts in the supplied Ivy file. (At least I think this is Ivy's standard behavior, not that sbt configures Ivy).

However, there is no way to specify the dependency URL in the pom.xml file. How you handle this may depend on what you expect from your customers, but one rather general solution is to declare the dependency as optional:

 libraryDependencies += "log4jdbc" % "log4jdbc" % "1.1" % "compile,optional" from "http://log4jdbc.googlecode.com/files/log4jdbc4-1.1.jar" 

Customers must explicitly declare a dependency to use it. Since this is not a repository, sbt users will still have to duplicate the from "..." declaration. Maven users can only use dependencies in the repository, although they can easily install it in the local repository.

+5
source

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


All Articles