lein-junit / lein-junit

Leiningen plugin for running JUnit tests.
26 stars 22 forks source link

separate paths and jar #26

Open tkruse opened 9 years ago

tkruse commented 9 years ago

Hi,

I am new to leiningen, and I am evalutating it for pure Java projects (for fun). I am used to separate project files in a tree like this:

root
- src
-- main
--- clojure
--- java
--- resources
-- test
--- clojure
--- java
--- resources

Then I would like to:

Now I would like to do that with leiningen, my code so far:

(defproject ...
  :profiles {:dev {:dependencies [[junit/junit "4.11"]]}}
  :source-paths ["src/main/clojure"]
  :java-source-paths ["src/main/java"]
  :test-paths ["src/test/clojure"]
  :junit ["src/test/java"]
  :junit-test-file-pattern #"^((?!Abstract).)*Test.java$"
  :resource-paths ["src/test/resources" "src/main/resources"]
  :jar-name "example.jar")

I miss :java-test-paths (not sure whether that is :junit), and :test-resource-paths

I do not know how to get leiningen to both test and create a Jar file, nor how to prevent it from compiling again. Finally that way both the .java and the .class files end up in my jar. Do I need to use profiles more, or do you have another suggestion?

I know not all of this relates to the junit plugin, feel free to ignore any aspect that I should ask elsewhere.

In case you care to reproduce, you could use my repo with these steps (on Linux):

git clone git@github.com:tkruse/build-bench.git
cd build-bench/
git checkout b86e6b568f5c2eeb91
make leiningen

then check build/leiningen/target/example.jar

tkruse commented 9 years ago

Ah, also, is there a way to suppress the junit test output? I tried LEIN_SILENT, but that is not honored for junit, apparently.

tkruse commented 9 years ago

Actually, unless I add the tests to the java-source path:

:java-source-paths ["src/main/java" "src/test/java"]

the tests are not run.

SourceNode commented 2 years ago

It also does not configure IntelliJ properly for running JUnit tests within the IDE. I have to manually mark directory test/java as "Test Sources Root". However, refreshing the IntelliJ project resets this. I have similar problems with it finding my log4j2.xml configuration file.

KingMob commented 2 years ago

Dirigiste just ran into this issue, too. We can't simultaneously run junit tests without adding them to :java-source-paths, but doing that tries to add the test classes to the jar file (and fails in our case, because junit is a test-only dep, and so it can't compile the test classes)

galdre commented 1 year ago

Ran into this issue. Addressed it by putting :java-source-paths ["test/java"] into the :dev profile. It gets merged with whatever :java-source-paths are provided for the project.

KingMob commented 1 year ago

@galdre That worked, thx!