leiningen

ghaskins 2024-02-09T12:27:53.786259Z

I have a hybrid clojure/java app and am seeing an issue where my project doesn’t automatically invoke javac on the java sources, and I dont understand why. I have done this in the past. Any tips on what to check?

ghaskins 2024-02-09T12:29:02.370179Z

I do have

:source-paths ["src/clojure"]
  :java-source-paths ["src/java"]
set, and I don’t have any prep-task overrides.

ghaskins 2024-02-09T12:34:18.465759Z

So far the only thing that has worked has been to set up a :precomp profile like

:profiles {:precomp {:java-source-paths ["src/java"]}
and then running
lein with-profile precomp javac

ghaskins 2024-02-09T12:35:21.909009Z

the fundamental issue seems to be that if I dont do this, it tries to process clojure files first…but the clojure code depends on the java code so it fails. I’ve done similar things in the past and it just worked, so I am scratching my head as to what is wrong in this project.

2024-02-09T22:30:35.050229Z

Have you altered prep-tasks anywhere?

ghaskins 2024-02-09T22:30:48.709609Z

Not to my knowledge

2024-02-09T22:31:14.270049Z

I’d double check that.

ghaskins 2024-02-09T22:31:32.573309Z

Theres nothing in the project file…but what I dont know is if some plugin may alter it

2024-02-09T22:31:36.460969Z

Use whatever profiles you are using and lein pprint it

ghaskins 2024-02-09T22:31:44.674019Z

ok

2024-02-09T22:31:44.762589Z

Hmm

ghaskins 2024-02-09T22:33:31.370039Z

When I pprint it, it looks like its the default

ghaskins 2024-02-09T22:33:32.978359Z

:prep-tasks ["javac" "compile"],

ghaskins 2024-02-09T22:34:48.556589Z

$ lein --version
Leiningen 2.10.0 on Java 21.0.1 Java HotSpot(TM) 64-Bit Server VM

2024-02-09T22:35:36.106819Z

That seems fine to me then. javac is first.

ghaskins 2024-02-09T22:35:46.636049Z

Yeah…its confounding

2024-02-09T22:36:01.379319Z

You can do DEBUG=true ahead of your lein command to get more details of what it is doing.

ghaskins 2024-02-09T22:36:09.438089Z

ok., let me try that

ghaskins 2024-02-09T22:39:40.247169Z

ok, that helped move the needle a bit. I immediately started with “DEBUG=true lein uberjar” to narrow it down and it actually did the right thing, giving me a hint that its not so much the overall config, but my flow

ghaskins 2024-02-09T22:40:13.787509Z

I have a Makefile and in there are other tasks like lein eastwood and lein cloverage that run before the build

2024-02-09T22:40:22.286549Z

Yes. Progress. So then figure out what your flow task is running.

ghaskins 2024-02-09T22:40:26.775239Z

so my problem seems to be i need to hook those the right way

2024-02-09T22:40:40.385079Z

That’s a possibility.

ghaskins 2024-02-09T22:42:07.343069Z

I dont know if this is meaningful to you, but when I enable debugging for one of the broken tasks

ghaskins 2024-02-09T22:42:09.188129Z

$ DEBUG=true lein cloverage
Leiningen's classpath: /usr/local/Cellar/leiningen/2.10.0/libexec/leiningen-2.10.0-standalone.jar
Applying task cloverage to []
Applying task javac to nil
Running javac with [@/var/folders/bl/s_t9lqxx2glgf9dv7h7z54g40000gn/T/.leiningen-cmdline84724007947143382.tmp]
Warning: environ value /Users/ghaskins/.jenv/versions/system for key :java-home has been overwritten with /Library/Java/JavaVirtualMachines/jdk-21.jdk/Contents/Home
Warning: protocol #'manetu.policyengine.api/policyengine is overwriting function test
WARNING: test already refers to: #'clojure.core/test in namespace: manetu.policyengine.api, being replaced by: #'manetu.policyengine.api/test
WARNING: test already refers to: #'clojure.core/test in namespace: manetu.policyengine.core, being replaced by: #'manetu.policyengine.core/test
Reflection warning, protojure/grpc/codec/lpm.clj:184:5 - reference to field close can't be resolved.
Exception in thread "main" Syntax error macroexpanding at (manetu/lambda_service/subservice/executor/wasm/guest_context.clj:1:1).

ghaskins 2024-02-09T22:42:33.662269Z

Of course, if I run the precomp profile or build the uberjar first, javac runs in the right timing

ghaskins 2024-02-09T22:43:03.037649Z

$ DEBUG=true lein uberjar
Leiningen's classpath: /usr/local/Cellar/leiningen/2.10.0/libexec/leiningen-2.10.0-standalone.jar
Applying task uberjar to []
Applying task javac to nil
Running javac with [@/var/folders/bl/s_t9lqxx2glgf9dv7h7z54g40000gn/T/.leiningen-cmdline15031772485933302220.tmp]
Compiling 35 source files to /Users/ghaskins/sandbox/git/mcp-lambda-service/target/uberjar/classes
Note: Annotation processing is enabled because one or more processors were found
  on the class path. A future release of javac may disable annotation processing
  unless at least one processor is specified by name (-processor), or a search
  path is specified (--processor-path, --processor-module-path), or annotation
  processing is enabled explicitly (-proc:only, -proc:full).
  Use -Xlint:-options to suppress this message.
  Use -proc:none to disable annotation processing.
Note: /Users/ghaskins/sandbox/git/mcp-lambda-service/src/java/io/github/kawamuray/wasmtime/Func.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

ghaskins 2024-02-09T22:43:29.549949Z

Im basically missing this in the broken cases

ghaskins 2024-02-09T22:43:30.922199Z

Compiling 35 source files to /Users/ghaskins/sandbox/git/mcp-lambda-service/target/uberjar/classes

2024-02-09T22:46:06.255879Z

When you run cloverage - you aren’t adding your profile precomp

2024-02-09T22:46:12.408469Z

So it isn’t getting the :java-source-paths.

ghaskins 2024-02-09T22:46:34.841809Z

well, to be clear, I set that in the top-level config, too. I only added the precomp profile as a hack

2024-02-09T22:46:51.462169Z

Ok, at the top-level I’d expect it to work there

ghaskins 2024-02-09T22:47:11.411809Z

yeah…and ive done this a bunch of other times in other projects, so its super weird

ghaskins 2024-02-09T22:47:21.153269Z

I cant figure out what I am doing differently

2024-02-09T22:47:26.542199Z

cloverage fails and eastwood?

2024-02-09T22:47:31.753769Z

are these custom :aliases?

ghaskins 2024-02-09T22:48:02.313099Z

no, i only have one alias for clj-kondo and I am not using it in this flow

ghaskins 2024-02-09T22:48:11.840669Z

its only lein-plugins

ghaskins 2024-02-09T22:48:36.753119Z

the operative part is

ghaskins 2024-02-09T22:48:38.516689Z

:source-paths ["src/clojure"]
  :java-source-paths ["src/java"]

  :repl-options {:init-ns user}

  :eastwood {:add-linters [:unused-namespaces]
             :exclude-linters [:unused-meta-on-macro :local-shadows-var :unused-ret-vals]}

  :profiles {:precomp {:java-source-paths ["src/java"]}
             :dev     {:dependencies   [[clj-http "3.12.3" :exclusions [commons-io]]
                                        [org.clojure/tools.namespace "1.4.5"]
                                        [criterium "0.4.6"]
                                        [eftest "0.6.0"]
                                        [clj-kondo "2023.12.15"]
                                        [mockery "0.1.4"]
                                        [integrant/repl "0.3.3"]]
                       :resource-paths ["jna/target" "jna/target/release" "test/lambdas"]
                       :aliases        {"clj-kondo" ["run" "-m" "clj-kondo.main"]}}
             :uberjar {:aot                :all
                       :omit-source        true
                       :target-path        "target/uberjar"
                       :uberjar-name       "app.jar"
                       :uberjar-exclusions [#".*manetu.*\.clj[xcs]*"]
                       :jvm-opts           ["-Dclojure.compiler.direct-linking=true"]}}

ghaskins 2024-02-09T22:49:11.699529Z

where

:profiles {:precomp {:java-source-paths ["src/java"]}
Was added in desperation as a hack

2024-02-09T22:50:31.601039Z

Did you try lein clean before DEBUG=true lein cloverage

ghaskins 2024-02-09T22:50:54.619299Z

I had hammered it with rm -rf target, but let me do it the right way and see what happens

2024-02-09T22:51:13.732109Z

ah ok, probably that covered it - just making sure you didn’t somehow have old classfiles somewhere causing issue

ghaskins 2024-02-09T22:51:48.887189Z

and as expected, same behavior

ghaskins 2024-02-09T22:52:33.212089Z

its like it ignores the java-source-paths when the source-paths [“src/clojure”] is present

ghaskins 2024-02-09T22:53:01.960489Z

or, maybe it schedules java-source-paths as secondary, but we never live long enough to get there

2024-02-09T22:54:02.703709Z

The default prep-tasks should run javac first and javac explicitly compiles the :java-source-paths that it finds.

2024-02-09T22:54:11.912819Z

So it is weird. It’s as if they are missing during certain tasks to me.

ghaskins 2024-02-09T22:54:20.766369Z

Makes sense…and thats what I thought…so confounding

2024-02-09T22:54:32.087439Z

odd, you have issues for both eastwood and cloverage

ghaskins 2024-02-09T22:54:51.174119Z

i didnt exhaustively look..let me try some of the other pre-build functions

2024-02-09T22:54:57.575519Z

But did you have issues with anything else before you tried using the profile precomp?

2024-02-09T22:55:30.707179Z

You said lein uberjar works with no special :aliases right? So it’d just be based on the top-level project.clj merged with the :uberjar profile.

ghaskins 2024-02-09T22:55:56.326509Z

right…i didnt try any other flows…i have a top level makefile that does this (currently)

ghaskins 2024-02-09T22:56:10.680449Z

all: scan test bin security-scan
precomp:
	lein with-profile precomp javac

scan: precomp
	lein cljfmt check
	lein bikeshed -l false -n false
	#lein kibit
	lein eastwood

ghaskins 2024-02-09T22:56:26.475689Z

and so it was puking somewhere in the scan

ghaskins 2024-02-09T22:56:43.014469Z

at the time, I didnt realize uberjar would actually work (should have thought to try that)

ghaskins 2024-02-09T22:56:59.117199Z

(the precomp was added as a workaround for this, that wasnt there originally)

2024-02-09T22:57:03.764719Z

So everything there is a plugin basically

ghaskins 2024-02-09T22:57:04.017659Z

it works with the precomp

ghaskins 2024-02-09T22:57:08.269279Z

correct

ghaskins 2024-02-09T22:57:24.657499Z

thats why I am wondering if its somehow related to the way the plugins interact

2024-02-09T22:57:41.217449Z

Yeah, with the precomp done first - you leave the classfiles in the :target-path and the other tasks will get them on their classpath

ghaskins 2024-02-09T22:57:54.769009Z

yep, that much I understood

ghaskins 2024-02-09T22:58:14.743229Z

the part I dont get is where lein is making the decision to compile the java-source-paths in some cases but not others

2024-02-09T22:58:34.078909Z

I don’t understand how every plugin would be susceptible to the same problem though. It isn’t something I’ve heard of I think.

ghaskins 2024-02-09T22:58:48.756619Z

Heh…i love when I find weird problems

ghaskins 2024-02-09T22:59:03.851149Z

Well, I feel better knowing that you dont know either

2024-02-09T22:59:06.313859Z

If it was one plugin, I’d wonder if it perhaps altered prep-tasks or didn’t merge with your project top-level - but even then that’d be pretty odd and probably always broken.

ghaskins 2024-02-09T22:59:09.315009Z

i was banging my head on the wall

2024-02-09T22:59:28.146689Z

When I have these issues, I deal with it a bit of the tedious way.

ghaskins 2024-02-09T22:59:39.476609Z

in any case, its largely academic at this point: my precomp hack works

ghaskins 2024-02-09T23:00:10.532679Z

i was hoping to just learn a more lein-idiomatic way, but maybe its elusive

2024-02-09T23:01:00.737569Z

I’ll basically git clone the lein version you want to deal with. Then I’ll launch a repl directly in leiningen and try to recreate the project setup via something like leiningen.core.project/read and then make sure I get the same profile configuration state and then look for things like :java-source-paths there etc. I probably could write a tiny post on this at some point, but it’s not that elegant.

2024-02-09T23:01:21.532629Z

Yeah, in worst-case, you could just script that you manually ensure the javac is ran correctly before each plugin task - like you have.

ghaskins 2024-02-09T23:03:25.448569Z

so, it looks like cljfmt is fine, probably because it doesnt need the classfiles present…bikeshed, eastwood, and cloverage all seem to suffer the same fate

ghaskins 2024-02-09T23:04:21.711099Z

in any case, ty for talking it through with me. I at least discovered that the uberjar target works, which at least instills some confidence in me that the config isnt fundamentally broken

ghaskins 2024-02-09T23:04:46.040249Z

something else is going on, but my hack in the makefile is fine for the time being

2024-02-09T23:06:56.227429Z

Ok, sounds good. I’m making a TODO to see if I can recreate your issue with a tiny project with cloverage as an example - to see if I can understand better what happened. I probably wont’ get to that for a few days though. I’ll let you know though if I find out anything interesting there.

👍 1
ghaskins 2024-02-09T23:07:16.881849Z

I appreciate your time, ty

👍 1