So I added this ```sourceSets { create("demoServ...
# community-support
c
So I added this
Copy code
sourceSets {
  create("demoServer") {
    java {
      srcDir("src/demoServer/java")
    }
  }
}

java {
  registerFeature("demoServer") {
    usingSourceSet(sourceSets["demoServer"])
  }
}
shouldn't I be able to do
Copy code
dependencies { demoServerImplementation("something") }
because that doesn't compile
v
Unfortunately not. You only get type-safe accessors for things that are created in plugins you apply in the
plugins { ... }
block. The type-safe accessors are necessary to compile the build script, so things you add in the build script cannot be added without the accessors, so you cannot execute it to know which accessors to generate. Btw. just creating the source set is enough, as the source dir you configure anyway is the convention. What you can do is
Copy code
val demoServerImplementation by configurations.existing
dependencies { demoServerImplementation("something") }
You just need a variable that is of type
Configuration
or
Provider<Configuration>
that you then can use in the
dependencies
block to declare dependencies.
The
Provider<Configuration>
though only works in recent Gradle versions and is incubating. So if you are shy to use incubating or are on an older Gradle version, you would use
getting
, not
existing
so that the variable is of type
Configuration
.
c
Btw. just creating the source set is enough, as the source dir you configure anyway is the convention.
are you saying I can delete code that I currently have?
v
Instead of
Copy code
sourceSets {
  create("demoServer") {
    java {
      srcDir("src/demoServer/java")
    }
  }
}
just
Copy code
sourceSets {
  create("demoServer")
}
or
Copy code
val demoServer by sourceSets.creating
t
You could also use:
Copy code
dependencies {
    "demoServerImplementation"("something")
}
though obviously you don't have the benefits of type-safe accessors (i.e. a typo in the configuration name won't be caught in the IDE, only when running Gradle)
☝️ 1
v
Actually then
Copy code
val demoServer by sourceSets.creating
java {
  registerFeature("demoServer") {
    usingSourceSet(demoServer)
  }
}
So in total
Copy code
val demoServer by sourceSets.creating

java {
  registerFeature("demoServer") {
    usingSourceSet(demoServer)
  }
}

val demoServerImplementation by configurations.existing

dependencies { demoServerImplementation("something") }
c
and now to ... FML, why can't intellij run this probably
properly*
this is the right way to depend on my own test fixtures right?
Copy code
demoServerRuntimeOnly(testFixtures(project))
t
testFixtures(project())
would be "more correct" (I think)
v
At least within the test suites block, it might even be necessary, not only "more correct"
c
this isn't a test suite, in fact it has to explicitly not be
because spring boot dev tools will turn itself off if certain jars are detected
actually calling it as a function
project()
results in a compile time failure
v
this isn't a test suite, in fact it has to explicitly not be
It is. The default
test
task is coming from a
test
test suite, whether you use the test suite DSL or not.
actually calling it as a function
project()
results in a compile time failure
How about
testFixtures(project(project.path))
?
c
... where are you getting a test task out of
demoServerRuntimeOnly(testFixtures(project))
?
v
Ah, sorry, babbling non-sense.
👍 1
Not about the last part though
While
testFixtures(project)
also works just fine here
What error do you get?
c
I mean, project.path doesn't fail, neither does project though. I seem to have it working. That's a fine detail I"m not clear on, I guess.
oh, I don't with
testFixtures(project)
it seems to work, but sometimes things that seem to work have surprising behavior, or don't
v
Ah, no, you did not get an error, just tried Thomas suggestion
I think
testFixtures(project)
is exactly right and Thomas was confused by using test suites DSL too much 😄
👍 2
c
I got an error with
testFixtures(project())
v
From within test suites DSL:
So
testFixtures(project)
or the more verbose
testFixtures(project(project.path))
which should do the same in normal dependencies block,
testFixtures(project())
in the test suites DSL dependencies block.
c
... Gods I love gradle's consistent apis. The real reason that we need reduced DSL is so that we can get a consistent API 🤣. I feel like Gradle would do itself a great favor just to figure out what API it wanted in create a new file that was maybe still kotlin but had a consistent API and threw out all of the inconsistencies and legacy support from that file. 🤣 And then start the process over again
v
Well, the test suites DSL is new and incubating. There a more type-safe dependencies approach is implemented. Once it is promoted to stable, who knows, maybe the normal dependencies block will follow suit with the new API. But without change there is no movement. And without backwards compatibility, you p*** off many users. 🤷‍♂️
c
Yeah hence new file blah blah blah. No big deal, but it explains the confusion...
t
You mean like declarative gradle? #C06JG95HREY😉
(and sorry for the confusion about
project
vs
project()
, I indeed worked quite a bit with testing suites recently 😇 )
c
Yeah jvm test suites are cool too.