is there a good way to build an application jar in...
# community-support
c
is there a good way to build an application jar in one "module" and then pull it into another but not on the classpath? I need to stand it up as a server for tests.
v
Define a custom
dependencyScope
configuration on which you define the dependency and a custom
resolvable
configuration extending from it, then use the resolution result of that configuration to get the jar and use it however you like
c
got a "how to" link for how to do that? since I've not done it before
t
Copy code
val server = configurations.dependencyScope("server")
val serverClasspath = configurations.resolvable("serverClasspath") {
  extendsFrom(server.get())
  // add attributes here for variant selection if needed
}
dependencies {
  server("…")
}
tasks {
  register<JavaExec>("runServer") {
    classpath = serverClasspath.get()
    mainClass = "…"
  }
}
v
☝️ And if on an older Gradle version or don't want to use incubating just create the configurations the classical way.
One slight variation,
val server by
instead of
val server =
, then you can save the
.get()
, as configurations are not treated lazily anyway.
c
thanks guys
t
Oh, TIL you can
by
such providers. Will refactor a few build scripts, thanks! 😉
v
iirc you can
by
all providers to
.get()
them.
Just in most situations you don't want or need an additional variable where you could use
by
but just
get
the original variable. But in some situations like here it is quite handy 🙂
👍 1