3

I have a WEBAPP MULTI PROJECT Gradle build with the below structure. I'm also using SPRING FRAMEWORK. I can't get the webapp to run in Jetty though as my bean files (dao-beans.xml) cannot be found. If I copy the bean files to the webapp build dir they're found but then Spring fails to instantiate my classes as it cannot find the classes on the classpath. What am I doing wrong?

+-- build.gradle
+-- dao-impl
¦   +-- src
¦       +-- main
¦       ¦   +-- java
¦       ¦   +-- resources
¦       ¦       +-- dao-beans.xml
¦       +-- test
¦           +-- java
+-- gradle.properties
+-- presenter
¦   +-- build.gradle
¦   +-- src
¦       +-- main
¦       ¦   +-- java
¦       ¦   +-- resources
¦       ¦   ¦   +-- beans.xml
¦       ¦   +-- webapp
¦       ¦       +-- WEB-INF
¦       ¦           +-- web.xml
¦       +-- test
¦           +-- java
+-- settings.gradle

Presenter's build.gradle:

apply plugin: "jetty"
apply plugin: "war"

jettyRun {
    httpPort = 8080
    scanIntervalSeconds = 3
}

War structure:

├── META-INF
│   └── MANIFEST.MF
└── WEB-INF
    ├── classes
    │   ├── beans.xml
    │   ├── *.classes
    │   └── logback.xml
    ├── lib
    │   ├── *.jar
    └── web.xml
aandeers
  • 431
  • 1
  • 6
  • 19
  • And how does the ':presenter' project have the dependency on the ':dao-impl' project ? How have you declared that matter in the presenter gradle configuration ? Please show more of the presenter project's gradle configuration in respect of dependencies. This answer maybe helpful (but modify as necessary for runtime dependencies, not just test) http://stackoverflow.com/questions/5644011/multi-project-test-dependencies-with-gradle – Darryl Miles Nov 18 '12 at 14:05

1 Answers1

1

You need to make your 'dao-impl' a free standing Java project (so the top level project builds it).

New file dao-impl/build.gradle

apply plugin: "java"

Instruct the top level project about the sub-project.

Then in existing presenter/build.gradle file add a dependency on that other project:

dependencies {
  ...
  compile project(':dao-impl').sourceSets.main.output
}

This should cause the JAR to be emitted in the deployed Jetty in the usual place WEB-INF/lib/dao-impl-x.y.z.jar (it might be better to do away with the .sourceSets.main.output if possible, but both forms should work)

Darryl Miles
  • 4,576
  • 1
  • 21
  • 20