You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
compile
This is the default scope, used if none is specified. Compile dependencies are available in all classpaths of a project. Furthermore, those dependencies are propagated to dependent projects.
Emphasis mine. Compile is the default scope and it is transitive.
However, rules_jvm_external compiles Maven's dependency specifications down into jvm_import.deps which itself is a JavaInfo.deps which behaves like a java_library.deps and which is not transitive.
Instead of compiling down to deps, it should probably use exports instead for Maven's compile dependencies. I modified @maven//jvm_import.bzl and @maven//BUILD locally to do just that, and confirmed that this made the example below work.
Example for reproduction:
This can be reproduced by a simple Java project that depends on ch.qos.logback:logback-classic (and only that as explicit dependency.) logback-classic in turn specifies org.slf4j:slf4j-api as a compile dependency in its pom file.
The Java source file in that project will import the org.slf4j package.
When compiled via Maven, this will compile just fine because org.slf4j is brought in as a transitive compile-time dependency:
$ mvn compile
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------< just.an.example:App >-------------------------
[INFO] Building App 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
...
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ App ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to /home/trittweiler/Src/experiments/maven/target/classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
However, the build will fail with bazel.
$ bazel build //src:App
INFO: Analyzed target //src:App (1 packages loaded, 7 targets configured).
INFO: Found 1 target...
ERROR: /home/trittweiler/Src/experiments/maven/src/BUILD:2:1: Building src/App.jar (1 source file) failed (Exit 1)
src/main/java/just/an/example/App.java:4: error: [strict] Using type org.slf4j.Logger from an indirect dependency (TOOL_INFO: "external/maven/v1/https/repo1.maven.org/maven2/org/slf4j/slf4j-api/1.7.25/slf4j-api-1.7.25.jar").
import org.slf4j.Logger;
^
Target //src:App failed to build
The files are:
├── pom.xml
├── src
│ ├── BUILD
│ └── main
│ └── java
│ └── just
│ └── an
│ └── example
│ └── App.java
└── WORKSPACE
Quoting Maven's documentation on "Dependency Scope":
Emphasis mine. Compile is the default scope and it is transitive.
However, rules_jvm_external compiles Maven's dependency specifications down into
jvm_import.deps
which itself is aJavaInfo.deps
which behaves like ajava_library.deps
and which is not transitive.Instead of compiling down to
deps
, it should probably useexports
instead for Maven'scompile
dependencies. I modified@maven//jvm_import.bzl
and@maven//BUILD
locally to do just that, and confirmed that this made the example below work.Example for reproduction:
This can be reproduced by a simple Java project that depends on
ch.qos.logback:logback-classic
(and only that as explicit dependency.)logback-classic
in turn specifiesorg.slf4j:slf4j-api
as acompile
dependency in its pom file.The Java source file in that project will import the
org.slf4j
package.When compiled via Maven, this will compile just fine because
org.slf4j
is brought in as a transitive compile-time dependency:However, the build will fail with bazel.
The files are:
The text was updated successfully, but these errors were encountered: