I have successfully migrated a java project within...
# general
r
I have successfully migrated a java project within my monorepo to pants (the rest of the monorepo is python). I have a
deploy_jar
target in my java project. The jar is required by one of python classes. Is there any way to represent this type of dependency a BUILD file?
🙌 1
h
Great to hear! How is the JAR loaded? As a resource file?
r
So, we are using Apache Flink's pyflink. We build some custom components using the flink java api that we need to make available to python. That jar is loaded locally by the client using py4j and is uploaded to the flink cluster when deploying jobs. Until now, we were building the jar and copying it into a lib dir within our python source tree. We created a resources target which includes the jar. I wasn't sure if there was a way to update the resources target to point to the jar that the package goal creates from a deploy_jar target.
Something I am used to in gradle but not sure how to do it in pants, or if it is supported.
h
I'm thinking the best way to approach this for now is via a new "codegen" plugin. You can have
deploy_jar
generate
ResourceSourceField
so that when you depend on it, it's like depending on
resource
but where it gets generated by ~running
./pants package
first https://www.pantsbuild.org/docs/plugins-codegen To do this, you'll want to add a private
sources
field to
deploy_jar
like this: https://github.com/pantsbuild/pants/blob/fe112bf20e9e7cfe4a2c746316ebc2655c428697/src/python/pants/core/target_types.py#L142-L145. You're just doing this to hook into codegen. Use a "plugin field" to extend the existing
deploy_jar
target: https://www.pantsbuild.org/docs/target-api-extending-targets Then, in your codegen rule, you'll call
await Get(BuiltPackage, DeployJarFieldSet, field_set)
I think. This essentially calls
./pants package
. You can then return the resulting
BuiltPackage.digest
in the
GeneratedSources
for your codegen rule We're happy to help more if you have questions along the way 🙂 Feel free to ask questions here or in #C01CQHVDMMW We may want to generalize that cross-language relationship in core Pants, but in the meantime
r
Cool - thanks for pointing me in the right direction. I'll dig in on my end 👍
h
My 2c: Today if a
python_sources
, say, depends on a
pex_binary
, then IIRC we package that PEX and make it available as a runtime resource for the python sources. This seems no different in principle, so we almost certainly want to support this in core Pants.
h
I thought that we only do that for
python_distribution
and then we install that into the venv via your PR from a few months ago?
h
Right but apart from that I thought we treated pexes as resources? Did I remember wrong?