Fork me on GitHub
#leiningen
<
2018-02-16
>
neupsh18:02:10

Hi all, is there a way to use maven parent project in leiningen?

neupsh18:02:38

I am trying to create a project.clj for a maven based project which is based on spring boot

neupsh18:02:08

and spring boot dependencies are managed using "managed-dependencies" based on a spring boot parent

neupsh18:02:48

i tried to use lein-parent (https://github.com/achin/lein-parent), but it seems like it only work for leiningen parent projects

neupsh18:02:51

basically trying to make something like this work: `

neupsh18:02:04

;; Spring boot parent project
  :parent-project {:coords [org.springframework.boot/spring-boot-starter-parent "1.5.10.RELEASE" :extension "pom"]
                   :inherit [:managed-dependencies]}

  ;; managed dependencies
  :managed-dependencies [[org.springframework.cloud/spring-cloud-dependencies "Edgware.SR2"]]

  :dependencies [
                 ;; Spring framework
                 ;; these are managed dependencies and versions are managed by parent
                 [org.springframework.cloud/spring-cloud-starter-oauth2 ]
                 [org.springframework.boot/spring-boot-starter-security]
                 [org.springframework.boot/spring-boot-starter-web]
                 [org.springframework.boot/spring-boot-starter-websocket]

                 [org.springframework.boot/spring-boot-starter-test :scope "test"]
                 [org.springframework.security/spring-security-test :scope "test"]

                 ;; h2 database
                 [com.h2database/h2 :scope "runtime"]

                 ;; clojure dependency :slightly_smiling_face:
                 [org.clojure/clojure "1.9.0"]]

gklijs19:02:54

Don't think it's a good idea to mix clojure with spring boot, what's the use case?

neupsh19:02:39

@gklijs I have existing spring boot application where i want to bring in clojure and clojurescript goodness in there.

neupsh19:02:40

Clojure was not a big problem, worked fine with maven, but for clojurescript, I found it easy to use cljsbuild with leiningen, and thus wanted to convert the maven pom to project.clj,

neupsh19:02:09

most of the things were easy to convert except for managed dependencies from parent

neupsh19:02:35

I will try to tinker a little bit with the lein-parent to see if i can do something with pom instead of a project.clj in the parent

greglook19:02:08

@neupsh https://github.com/amperity/lein-monolith works from the other direction; not sure if it’ll be useful, but you could get the metaproject to output a pom for consuming in maven perhaps?

neupsh19:02:33

@greg316 I don't think it will help, as I need a way to merge the :managed-dependencies of current project from the parent project distributed as pom

neupsh19:02:01

@greg316 to be honest, just looked for a while, so not entirely sure.

neupsh19:02:15

i will take a look probably over the weekend

sophiago23:02:47

Does :global-vars not work within a profile? I like to use *warn-on-reflection* and *unchecked-math* only during development so figured it'd be best to put them in a :user profile and launch it with lein with-profiles +user repl, but it's not throwing the few warnings I left.

greglook23:02:22

:user is active by default, so you shouldn’t need to use with-profiles for it

greglook23:02:49

you could try using lein-pprint or lein-cprint to debug

sophiago23:02:26

Oh, really? If it's active by default then why is it advised to not define it in project.clj?

greglook23:02:48

because some profiles such as user and system are meant to be used at the user and system level, respectively

greglook23:02:59

if you define them in a project, it overrides the profiles with the same name

sophiago23:02:10

Ah, gotcha.

noisesmith23:02:15

putting :user in project.clj imposes what should be individual preferences on everyone developing a project

greglook23:02:22

similarly, if you put a :dev profile in ~/.lein/profiles.clj and had a :dev profile in project.clj, you’d only see the config from your project

sophiago23:02:14

So, it seems I have two issue here: 1. What profile do I actually want to use for something like this? 2. Regardless, why aren't my :global-vars working?

greglook23:02:29

I think :user (in your user-level profiles) is appropriate for what you want to do

sophiago23:02:59

Well, I actually don't want it to load by default whenever I open a repl.

greglook23:02:59

you could install https://github.com/greglook/lein-cprint and run lein cprint :global-vars to see what leiningen thinks the compose project definition looks like

sophiago23:02:13

Oh, that's what you meant. Got it.

greglook23:02:43

> I actually don’t want it to load by default whenever I open a repl. Maybe what you want is lein check for the reflection warnings?

sophiago23:02:13

Yeah, lein check is nice but I'd like to warn on boxed math as well 😕

greglook23:02:25

alternately, you could make a profile that you turn on deliberately:

{:global-warnings {:global-vars {,,,}}
 :user {:aliases {"noisy-check" ["with-profile" "+global-warnings" "check"]}}}
(untested)

sophiago23:02:56

Yeah, that looks like what I want. Let me try it out.

greglook23:02:37

works for me!

sophiago23:02:32

I still must be confused about something...what command are you using to launch it?

greglook23:02:10

I added the profile above and ran the command and it warned me about some issues (in dependencies, but still)

greglook23:02:22

where are you putting your profiles.clj file?

sophiago23:02:38

/.lein/profiles.clj

greglook23:02:57

I’m assuming there’s a $HOME in front of that

sophiago23:02:59

You're just running lein noisy-check?

sophiago23:02:17

That's local to my project. I might be really confused here 😛

noisesmith23:02:29

project/.lein is nothing

greglook23:02:33

then you don’t need the .lein

noisesmith23:02:59

I mean, project/.lein/ can exist, but nothing looks for anything there

greglook23:02:00

you can have user-level profiles in ~/.lein/profiles.clj or ~/.lein/profiles.d/{profile}.clj

greglook23:02:15

you can have project-level profile overrides in ./profiles.clj

greglook23:02:26

which is useful to put in .gitignore and keep environment configs you don’t want to check in

greglook23:02:36

and then there’s the regular profile lookup in project.clj

greglook23:02:17

so I usually have a profiles.clj in each project with something like this in it:

{:local ^:repl
 {:env {:my-var "foo"
        ,,,}
  ,,,}}

sophiago23:02:17

It seems to be working now that I put it in just ./profiles.clj but I get that warning about :user level profile in project files. The behavior for check also runs through everything I have in source whereas I'd prefer just the namespaces I require at the top level 😕

sophiago23:02:42

I assume for the first part I should be using :local instead?

greglook23:02:01

ah, if it’s project-local then yes, don’t use :user for it

greglook23:02:15

:local isn’t anything special to leiningen btw, just the obvious name choice 🙂

sophiago23:02:34

Yeah, got that. But since it's not default I can't use your cool :noisy-check alias. That's nice, although not sure if it's what I want considering it checks files I have essentially as scratch

greglook23:02:45

yeah, might make more sense to stick into your user-level profiles if you want the alias to be available by default

greglook23:02:05

I don’t know of a way to restrict the files that check operates against - it does a full test-compile of your source code

sophiago23:02:42

But I can still use :global-warnings to launch a repl and get the behavior I want, right?

greglook23:02:42

other than putting your scratch code into another directory and adding a :source-paths entry to the :repl profile (or something else not active by default)

greglook23:02:52

yeah, that ought to work

noisesmith23:02:02

you could make a replacement for check that starts with your :main or :init-ns instead of eagerly checking every file in the tree

noisesmith23:02:24

check is simple enough that shouldn’t be hard

greglook23:02:27

unless… it’s possible the global-vars might not apply to the repl process, since that gets launched separately from lein :thinking_face:

greglook23:02:35

would be interested to hear your results

sophiago23:02:42

Wait so first things first... @greg316 what exactly do you mean by user-level profiles?

sophiago23:02:59

In order to avoid the warning I mean.

greglook23:02:16

in your home directory, as opposed to inside a project

greglook23:02:40

so ~/.lein/profiles.clj or ~/.lein/profiles.d/user.clj would both be user-level

sophiago23:02:59

Oh I see. No, I'm just trying to define it at the project level and avoid that warning.

greglook23:02:51

well, if you only want these available in the one project, you could put the :noisy-check profile in your project.clj and then put the alias directly in the project file

greglook23:02:50

I don’t think there’s a way to have the alias available by default (without adding it to project.clj), but if you don’t mind typing lein with-profile +noisy-check check then you could just put the :noisy-check profile in your project-local profiles.clj

sophiago23:02:03

Ah, ok. Finally got that part 😛

sophiago23:02:15

@noisesmith would you mind advising re: overriding check?

sophiago23:02:29

(not so necessary, but a nice convenience)

noisesmith23:02:43

all check does is call compile on each file on disk

sophiago23:02:52

Could I just replace it in my alias with something like "compile core" if core is my main ns?

noisesmith23:02:01

calling compile on the one file with your main or init-ns should also transitively give you warnings about everything required

noisesmith23:02:40

right, it’s the clojure compile function so it would be (compile some.ns)

noisesmith23:02:59

(with warn-on-reflection and warn-on-boxed turned on, of course)

sophiago23:02:47

Woohoo, thanks!

sophiago23:02:42

As should be painfully obvious, I've gotten by for a long time now not really understanding leiningen...

greglook23:02:23

it can be mysterious wizard

greglook23:02:42

not too bad under the hood once you dig in though

greglook23:02:04

would recommend playing with lein-cprint as a way to understand what profiles do to the project definition 🙂

sophiago23:02:48

Yeah, thanks for the tip. And I agree, compared to...um...some other build tools I've had to use lein is much simpler.