tools-build

liebs 2022-11-22T15:50:17.542149Z

Hi, I am trying to use the Cognitect AWS API from Java. I have this .clj file:

(ns bhlieberman.s3.client
  (:require [cognitect.aws.client.api :as aws]
            [cognitect.aws.credentials :refer [basic-credentials-provider]])
  (:import [javax.imageio ImageIO]
           [ File BufferedInputStream]))

(gen-class
 :name bhlieberman.s3.client.Client
 :main false
 :prefix "-"
 :methods [^{:static true} [getImage [obj] void]])

(defn write-image [^BufferedInputStream is]
  (-> is ImageIO/read (ImageIO/write "jpg" (File. "test.jpg"))))

(defn -getImage [obj]
  (let [s3 (aws/client {:api :s3
                        :region "us-west-2"
                        :credentials-provider
                        (basic-credentials-provider {:access-key-id (System/getenv "AWS_ACCESS_KEY_ID")
                                                     :secret-access-key (System/getenv "AWS_SECRET_KEY")})})
        opts {:op :GetObject
              :request {:Bucket "images"
                        :Key obj}}]
    (-> s3 (aws/invoke opts) :Body write-image)))
I guess I'm not sure if this is properly a tools-build Q, but when I compile this into a .jar (compilation works fine) and put it in my build.gradle, I can't import it as import bhlieberman.s3.client.Client. I think I ought to be able to do that. I tried specifying the .jar itself as a Gradle dep and also the entire /target directory. Neither works.

Alex Miller (Clojure team) 2022-11-22T15:51:42.749389Z

Does the jar have classes in it?

liebs 2022-11-22T15:54:36.341949Z

Meaning other classes besides the gen-class'ed Client?

liebs 2022-11-22T15:55:47.906719Z

Before I switched to tools-build for this and was just using compile at the REPL it was outputting class files for every function in the namespace, which I understand to be the expected behavior.

liebs 2022-11-22T15:57:45.739889Z

These are the contents of the outputted /target dir.

liebs 2022-11-22T16:06:44.554339Z

I learned about jar tf jar-file all of about 30sec ago, but here's the output of that:

jar tf .\s3.client-0.0.1.jar
META-INF/MANIFEST.MF
bhlieberman/
META-INF/
bhlieberman/s3/
META-INF/maven/
bhlieberman/s3/client.clj
META-INF/maven/com.bhlieberman/
META-INF/maven/com.bhlieberman/s3.client/
META-INF/maven/com.bhlieberman/s3.client/pom.properties
META-INF/maven/com.bhlieberman/s3.client/pom.xml

Alex Miller (Clojure team) 2022-11-22T16:07:12.148989Z

So no classes

Alex Miller (Clojure team) 2022-11-22T16:07:20.725609Z

So how are you compiling?

liebs 2022-11-22T16:07:40.435239Z

clj -T:build jar

Alex Miller (Clojure team) 2022-11-22T16:08:14.532269Z

And does your build script compile classes?

liebs 2022-11-22T16:10:06.750489Z

I guess it does not. Do I need to add compile-clj to my build script?

Alex Miller (Clojure team) 2022-11-22T16:11:28.539239Z

Yes

Alex Miller (Clojure team) 2022-11-22T16:12:04.920239Z

There are some examples at https://clojure.org/guides/tools_build

🤝 1
liebs 2022-11-22T16:15:50.755809Z

Thank you Alex!