Bazel: Cannot redefine repository after any load statement in the WORKSPACE file

Created on 23 Feb 2016  路  6Comments  路  Source: bazelbuild/bazel

Bazel version: 0.2.0 (with a cleared cache)

ERROR: /home/pzd/ffruit/WORKSPACE:15:1: Traceback (most recent call last):
        File "/home/pzd/ffruit/WORKSPACE", line 15
                commons_compress()
        File "/home/pzd/ffruit/third_party/java/commons_compress/workspace.bzl", line 3, in commons_compress
                native.maven_jar(name = "commons_compress", artifac...")
Cannot redefine repository after any load statement in the WORKSPACE file (for repository 'commons_compress').
ERROR: Error evaluating WORKSPACE file.
ERROR: no such package 'external': Package 'external' contains errors.

WORKSPACE: https://gitlab.com/perezd/ffruit/blob/master/WORKSPACE
workspace.bzl: https://gitlab.com/perezd/ffruit/blob/master/third_party/java/commons_compress/workspace.bzl

Any idea what happened here? This used to work just fine.

Most helpful comment

Ideally the error message would contain ".. previously defined here :"

All 6 comments

Ah! Thank you for that. It'd be nicer if it told me where I first defined it...that is a bug on my side!

I'm not sure what the right thing to do here is. It's not so nice to rely on a 3rd party dependency to bring in a dependency the rest of your code depends on, and you also don't really want to have to edit 3rd party dependencies' build files... at the same time we probably don't want to allow duplicate rule definitions.... Maybe we need some kind of "is this rule already defined" mechanism. That could turn the skylark code ugly though because then you'd basically have to guard each rule call with something like 'if not isdef("some_library"): native.maven_jar(name = "some_library")'. Then of course there's conflicting versions: one thing could ask for commons_compress v1.5 and another thing could ask for 1.6, and if they're not named something like commons_compress_1_5 and commons_compress_1_6 then it's more complicated to resolve the problem.

Yeah, this gets gross. At least you did catch a bug I caused :)

native.existing_rules() exposes the list to implement something like the isdef you mentioned (maybe even do a _maven_jar_maybe function to avoid having to write it everywhere). Not the nicest thing, but it does give you options.

Ideally the error message would contain ".. previously defined here :"

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dslomov picture dslomov  路  84Comments

meisterT picture meisterT  路  98Comments

laurentlb picture laurentlb  路  76Comments

philwo picture philwo  路  70Comments

keith picture keith  路  71Comments