And implement `prepare_resources` trivially
# general
h
And implement
prepare_resources
trivially
p
benjyw: sorry to bother you again .. if you happen to have a second .. mind having a quick look at my current implementation?
h
You shouldn’t need to add anything to the resources or the classpath
You just need to write your files under chroot
Pants takes care of everything else
What does your
find_all_relevant_resources_targets(self)
look like?
p
Copy code
def find_all_relevant_resources_targets(self):
            # <http://self.context.log.info|self.context.log.info>('targets={}'.format(self.context.targets()))
            def is_jvm_app(target):
                return isinstance(target, JvmApp)
            jvm_apps = self.context.targets(predicate=is_jvm_app)
            return jvm_apps
I am targeting the
JvmApp
at the moment ..
And the
BUILD
file is as follows:
Copy code
scala_library(..)

jvm_binary(
    name='bin',
    dependencies=[
        ':data-service-lib',
    ],
    main='service.data.DataServer',
)


jvm_app(
    name='app',
    basename='data-service',
    binary=':bin',
)
Ah now I get it.
.execute
in
ResourcesTask
is already adding the
chroot
to the classpath .. In your previously mentioned implementation of
ResourcesTask
, what fingerprint strategy did you end up using?
h
the default one
It happened to work for what I needed
p
cool. and in your case, after executing
/pants bundle foo:app
you would have seen the generated resource inside the jar?
hi @happy-kitchen-89482 .. I finally made it thanks to your help and some reading-between-the-lines from @acceptable-scooter-37412 ‘s messages
h
greast
great
p
turns out: 1.
JvmApp
can’t have resources .. I now attached it to the
JvmBinary
instead 2. if there are no
resources=[..]
on the
JvmBinary
defined inside the
BUILD
file, it won’t pick up any resources at all .. so now I simply added a n empty
resources=[]
target
for 2. I am wondering if this is expected behaviour .. maybe worth filing an issue for it on github 🤔
.. aaand now i’m stuck as to why the generated resource doesn’t show up when doing
./pants bundle .. --bundle-jvm-deployjar
🤔
@happy-kitchen-89482 are your generated resources included in the resulting deployjar when running
./pants bundle .. --bundle-jvm-deployjar
?
h
Let me check
That wasn’t in my use case, so I’m not sure offhand
p
.. and apologies for the ongoing questioning. I hope by writing it out here it will help others in the future ..
h
No problem
Hmm, no, I’m not seeing the files in my bundle
p
@witty-crayon-22786 my message [1] about
JarTool
was related to this thread .. [1] https://pantsbuild.slack.com/archives/general/p1486653980002201
thanks @happy-kitchen-89482 for checking
Last night I looked a bit deeper into
JarTool
. There are unit tests explicitly testing the “add directory => all files within the directory will be added” case
h
@purple-oil-45048 what’s the current status? Still stuck?
p
Yeah. I’ve narrowed it down to
jar_task.Jar#_add_entry
and
#_render_jar_tool_args
.. I think this is where things get lost
I’ve got a proof-of-concept available on https://github.com/suls/pants-generated-resources
what’s the difference?
Copy code
- COMMAND="./pants run src/java/org/suls/pants:app"
  - COMMAND="./pants bundle src/java/org/suls/pants:app && $JAVA_BIN -jar dist/src.java.org.suls.pants.app-bundle/main.jar"
  - COMMAND="./pants bundle src/java/org/suls/pants:app --bundle-jvm-deployjar && $JAVA_BIN -jar dist/src.java.org.suls.pants.app-bundle/main.jar"
The last command with
--bundle-jvm-deployjar
fails to include/bundle the generated resource https://github.com/suls/pants-generated-resources/blob/master/pants-plugins/src/python/org/suls/pants/register.py
@happy-kitchen-89482 and @witty-crayon-22786 if you have a minute I’d very much appreciate your input
w
according to what query?
h
I’m finding the new “threads” feature in Slack more confusing than helpful...
I would expect bundle to cram all the resources from the runtime classpath into the bundle
Let me see what’s up
I wonder if the problem is that the targets you’re acting on aren’t Resources targets
What happens if you create a Resources target adjacent to (and a dependency of) your JvmApp target, and inject the properties file onto that Resources target in your custom task?
p
This sounds like a very good idea in fact. How can I get a handle on a resources target of an
JvmApp
? So far I've been using
context.target(predicate=
hook .. but I don't see how I can say give me the X that is a dependency of Y
h
Hmm
You can’t really
not easily, anyway
You’ll need some other way to identify this resources target in your task
naming convention?
Hmm, actually, not so true
You can capture all the JvmApp targets in the context, like you do now
And then look at the resources targets that are direct dependencies of those
So start with Y, and find X, so to speak
Does that make sense?
Or -
You can synthesize a Resources target in your custom task
and inject it into the build graph as a dependency of the JvmApp target
that might be easier and less weird than having a hand-written, empty resources target in your BUILD file next to each jvm_app, with a comment saying that its files will be generated by the custom task.
There should be examples of this lying around
p
I will look into this synthetic stuff. You mentioned it already before and I’ve seen it a couple of times in the code .. seems to be a fairly important concept. Anyways, thanks for helping me with this @happy-kitchen-89482 and @witty-crayon-22786 !
h
No problem - let us know how it goes and if you run into further difficulty!
p
👍