talios / clojure-maven-plugin

Apache Maven Mojo for compiling clojure scripts to class files
252 stars 74 forks source link

surefire java junit tests can't load resources from classpath #68

Closed h908714124 closed 11 years ago

h908714124 commented 11 years ago

Trying to integrate some clojure namespaces into an existing java project.

There are existing java unit tests in src/test/java and test resources in src/test/resources. For example, src/test/resources/META-INF/persistence.xml is loaded from the test classpath by some tests (via hibernate).

Unfortunately though, the resources from src/test/resources are not moved to target/test-classes when the clojure-maven-plugin is in the pom. Moving the test resources to src/test/clojure/ did not help. Specifing things like testResourcePath in or also did not help.

This command reproduces the problem:

mvn clean test

This is the directory layout: src/main/java src/test/java src/test/resources

It succeeds when there is no clojure-maven-plugin in the pom, and fails when it's there. Sorry for the relative brevity of this bug report, I hope to upload a demo project soon if I find the time.

h908714124 commented 11 years ago

Demo: clojure-maven-plugin-demo

gslowikowski commented 11 years ago
          <process-test-resources>
            org.apache.maven.plugins:maven-resources-plugin:testResources
          </process-test-resources>

has to be added to "src/main/resources/META-INF/plexus/components.xml" file.

gslowikowski commented 11 years ago

I mean https://github.com/talios/clojure-maven-plugin/blob/develop/src/main/resources/META-INF/plexus/components.xml, not demo project file :)

h908714124 commented 11 years ago

@gslowikowski didn't work, maybe xml element order matters?

h908714124 commented 11 years ago

This didn't work:

<phases>
  <clean>
    org.apache.maven.plugins:maven-clean-plugin:clean
  </clean>
  <generate-sources>
    com.theoryinpractise:clojure-maven-plugin:add-source
  </generate-sources>
  <process-resources>
    org.apache.maven.plugins:maven-resources-plugin:resources
  </process-resources>
  <compile>
    org.apache.maven.plugins:maven-compiler-plugin:compile,com.theoryinpractise:clojure-maven-plugin:compile
  </compile>
  <generate-test-sources>
    com.theoryinpractise:clojure-maven-plugin:add-test-source
  </generate-test-sources>
  <process-test-resources>
    org.apache.maven.plugins:maven-resources-plugin:testResources
  </process-test-resources>
  <test-compile>
    org.apache.maven.plugins:maven-compiler-plugin:testCompile,com.theoryinpractise:clojure-maven-plugin:testCompile
  </test-compile>
  <test>
    org.apache.maven.plugins:maven-surefire-plugin:test,com.theoryinpractise:clojure-maven-plugin:test
  </test>
  <package>
    org.apache.maven.plugins:maven-jar-plugin:jar
  </package>
  <install>
    org.apache.maven.plugins:maven-install-plugin:install
  </install>
  <deploy>
    org.apache.maven.plugins:maven-deploy-plugin:deploy
  </deploy>
</phases>
talios commented 11 years ago

Hey all, I was meaning to look at this now and I see a big swath of discussion already :-)

I suspect as well as well as adding the missing test resource back into the lifecycle, we might need to add some dependency annotations on the test goal as well.

Lets give this a spin!

gslowikowski commented 11 years ago

Hi

It works for me, order is not important. @talios I'm not an expert, but your configuration in "components.xml" file looks different from what I use in my Maven plugin: http://maven-play-plugin.googlecode.com/svn/trunk/plugin/play-maven-plugin/src/main/resources/META-INF/plexus/components.xml. I mean configuration->lifecycles->lifecycle->phases instead configuration->phases. Maybe it doesn't matter?

talios commented 11 years ago

I have a commit ready to push, and have moved the demo project in as an IT test...

@gslowikowski Hrm - I don't think it matters, it looks like your defining a named lifecycle which you can fork, whereas I'm just replacing the default lifecycle as a whole.

I'll push my commit, then if one you guys wants to verify it's all shiny I'll push a release to central.

PS: Any of you lurk on #clojure on freenode? Say hi...

gslowikowski commented 11 years ago

Side note I'm not defining new cycles for forking, I'm defining mojos to execute in the predefined ("clean" and "default") ones, using their names.

talios commented 11 years ago

Ahh - so that means you only define your own goals, and don't squash out the standard ones like I did here? Mmmm, maybe that would be a better option to explore then...

gslowikowski commented 11 years ago

If I remember, I made id based on maven-bundle-plugin (defining 'bundle' packaging for OSGI artifacts) http://svn.apache.org/repos/asf/felix/releases/maven-bundle-plugin-2.3.7/src/main/resources/META-INF/plexus/components.xml. This is well known and popular packaging, so I trust, it has a proper way of defining custom packaging. In my plugin I define my own goals AND the standard ones where appropriate.

talios commented 11 years ago

1.3.16 has been released and should make its way to Maven Central within an hour or few :)