Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java Source Path #434

Closed
AshtonKem opened this issue Jan 12, 2016 · 17 comments
Closed

Java Source Path #434

AshtonKem opened this issue Jan 12, 2016 · 17 comments

Comments

@AshtonKem
Copy link

I have a mixed java/clj project that I'm trying to add lein-cljsbuild to. Unfortunately when trying to run lein cljsbuild once I get ClassNotFoundExceptions due to the java sources included on java-source-path. I believe this is made worse by #362.

@mneise
Copy link
Collaborator

mneise commented Jan 23, 2016

Could you please post your build configuration? Also, I assume you are trying to use lein-cljsbuild to build ClojureScript and not the java/clj part of your project?

@AshtonKem
Copy link
Author

For some reason, I can no longer reproduce this problem. It must've been a version bug (I'm still scaffolding out the basics of cljs on this project), or some sequencing of timing bug I can't reproduce anymore.

I guess close this bug, I'll report back here if I start seeing it again.

Ashton

Sent from my iPhone

On Jan 23, 2016, at 2:17 AM, Maria Geller (Neise) notifications@github.com wrote:

Could you please post your build configuration? Also, I assume you are trying to use lein-cljsbuild to build ClojureScript and not the java/clj part of your project?


Reply to this email directly or view it on GitHub.

@mneise mneise closed this as completed Jan 23, 2016
@AshtonKem
Copy link
Author

Figured out how to recreate it, it had to do with running lein cljsbuild on its own, not via figwheel-sidecar as I'd switched to.

I've created a sample repo that demonstrates the problem.

@mneise mneise reopened this Feb 19, 2016
@mneise
Copy link
Collaborator

mneise commented Feb 19, 2016

Thank you for the repo. You are trying to use lein-cljsbuild for something that it was not built for, namely compiling Clojure. Instead, lein-cljsbuild is a plugin that uses the ClojureScript compiler to compile ClojureScript source files and not Clojure source files 😉

@mneise mneise closed this as completed Feb 19, 2016
@AshtonKem
Copy link
Author

I don't think I was very clear, or my proposed solutions were just wrong.

The issue appears to be that lein-cljsbuild is attempting to process .clj files in a src directory that contains a mix of cljc, cljs, and clj files. This causes errors that are completely unrelated to the successful compilation of my cljs sources, but are still really annoying to the user. As far as I could tell, this could be fixed by:

  • Either lein-cljsbuild or the cljs compiler ignoring .clj files
  • Me separating my clj and cljs/cljc files into different directories.

The former seems better to me, as there is no real reason for cljs to touch clj files in my opinion. The latter I can implement myself, but strikes me as cumbersome.

@mneise
Copy link
Collaborator

mneise commented Feb 22, 2016

@AshtonKem Yes, the convention is to put your ClojureScript and Clojure files in separate directories. The ClojureScript compiler actually also needs to process some .clj or .cljc files, since ClojureScript macros are written in Clojure 😉

@AshtonKem
Copy link
Author

I understand that it needs to process .cljc files, but I'm a bit
confused on why it process .clj files. Can any artifacts from clj file
compilation affect cljs/cljc output?

Ashton

"Maria Geller (Neise)" notifications@github.com writes:

@AshtonKem Yes, the convention is to put your ClojureScript and Clojure files in
separate directories. The ClojureScript compiler actually also needs to process
some .clj or .cljc files, since ClojureScript macros are written in Clojure
😉


Reply to this email directly or view it on GitHub.

Ashton

@mneise
Copy link
Collaborator

mneise commented Feb 22, 2016

Yes, as I said, ClojureScript macros are written in Clojure and therefore have to be in a .clj file.

@AshtonKem
Copy link
Author

Well, that's unfortunate then. Guess there's nothing to be done.

Ashton

@w01fe
Copy link

w01fe commented Apr 25, 2016

I'm also running into this issue. I've written a java Class that I would like to be able to access as part of ClojureScript compilation.

@mneise
Copy link
Collaborator

mneise commented Apr 25, 2016

You only can use Java in your ClojureScript project when writing a macro, since macros in ClojureScript are written in Clojure.

@w01fe
Copy link

w01fe commented Apr 25, 2016

Thanks -- I'm aware of that, and that is the case I would like to support. Specifically, I would like to use a Java class in the Clojure implementation of Schema, but currently this breaks the abilities to use schemas in macros that generate ClojureScript.

@mneise
Copy link
Collaborator

mneise commented May 8, 2016

@AshtonKem I just had a look again at your example repo, and one way to make it work it to add :source-paths ["src" "target/classes"] to your project config and then run lein do javac, cljsbuild once.

I though that javac would run anyway before any plugin tasks are executed and that we wouldn't have to explicitly add target/classes to the classpath, so need to check why this is not the case.

@w01fe Maybe this workaround also helps in your case?

@mneise mneise reopened this May 8, 2016
@w01fe
Copy link

w01fe commented May 8, 2016

@mneise Thanks -- I also just realized that this probably wouldn't have been an issue for users of schema (just the tests within the project), since the compiled Java class would be in the published jar and thus on the classpath for downstream users. In any case, I ended up going a different route that didn't require a custom Java class.

@aiba
Copy link

aiba commented Mar 16, 2017

I also have this issue. A cljs file depends on a macro that depends on a java file in :java-source-paths. Running lein cljsbuild once throws a ClassNotFoundException.

The workaround of adding "target/classes" to :source-paths is not helping me because my project specifies :target-path "target/%s/". So classes end up in target/base+system+user+dev+cljs+b9e56754/classy-files, and I'm not sure I should copy/paste that string into project.clj.

I though that javac would run anyway before any plugin tasks are executed and that we wouldn't have to explicitly add target/classes to the classpath, so need to check why this is not the case.

It would be awesome if we could figure this out.

@mneise
Copy link
Collaborator

mneise commented Jul 24, 2017

The reason for the mentioned ClassNotFoundException is that lein javac didn't run as a prep-task when running lein cljsbuild. I've fixed this in 1.1.7-SNAPSHOT and will do a release soon.

@mneise mneise closed this as completed Jul 24, 2017
@mneise mneise added this to the 1.1.7 milestone Jul 27, 2017
@mneise mneise added the Bug label Jul 27, 2017
@mneise
Copy link
Collaborator

mneise commented Jul 28, 2017

Has been fixed with 0d085f9.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants