abergmeier
abergmeier

Reputation: 14052

Force target to be rebuilt

I have the need to, after building targets, trigger a deploy of these.

To really not waste any time I would like to have that as a build rule. Now for that to work I would like to have the deploy be done every time. So the question is:

How do I force a target to be rebuilt from scratch deterministically?

Upvotes: 4

Views: 7090

Answers (1)

kris
kris

Reputation: 23592

It would be more bazel-y to do this as a second step, e.g.,

java_binary(
    name = "target1",
    ...
)

java_binary(
    name = "target2",
    ...
)

sh_binary(
    name = "deploy-targets",
    srcs = ["deploy-targets.sh"],
    data = [":target1.jar", ":target2.jar", ...],
)

Then do bazel run //path/to:deploy-targets when you want to deploy.

deploy-targets.sh would look something like:

#!/bin/bash

for t in $(ls ws/path/to/*.jar); do
  mvn deploy:deploy-file -Dfile=$t ...
done

Actions (which are what happen during a build) are not supposed to interact with the outside environment, so deploying kind of breaks that contract. run, on the other hand, can do anything, it's just running a binary.

Using run would also solve your "run every time" problem: Bazel can't "cache" forking a binary.

Upvotes: 1

Related Questions