This message was deleted.
# plugin-development
s
This message was deleted.
j
I think it doesn't exist, currently I am publishing to a local test maven repository
Copy code
tasks.testDependsOnPublishToMavenLocalTestFrom(projects.composeResources)
If you need more details, I can share with you how that task is implemented
s
Thanks Javi. That is unfortunate; seems like a commonish set up. I think I'll look into the GradleRunner source and see if I can unravel how that might be accomplished.
t
You can add your other projects inside that "withPluginClasspath" by adding them to the
pluginUnderTestMetadata
task's
pluginClasspath
.
Copy code
val additionalPluginClasspath by configurations.creating
dependencies {
    additionalPluginClasspath(project(":foo"))
}
tasks {
    pluginUnderTestMetadata {
        pluginClasspath.from(additionalPluginClasspath)
    }
}
then
withPluginClasspath
inside the tests will have project ":foo" in it.
s
We try very hard to neither publish to nor consume from mavenLocal. It has caused me problems many times
@Thomas Broyer OMG. Thank you!!
I assume
pluginClasspath.from(additionalPluginClasspath)
is additive?
t
Yes.
setFrom()
(or
from =
) would replace the default value.
v
We try very hard to neither publish to nor consume from mavenLocal. It has caused me problems many times
Very wise actually, as it is not a pure repo, but also a caching proxy for Maven. πŸ™‚ But what you can always do too is to publish to a different local repository, just some path somewhere, for example in the
buildDirectory
. Unless you need it for cross-build coordination, it is probably always preferable over
mavenLocal()
.
πŸ‘πŸΌ 1
s
I must have missed something. I have this, based on your snippet:
Copy code
configurations {
	additionalPluginTestClasspath
}

dependencies {
    ...

    implementation project(':hibernate-core')
	additionalPluginTestClasspath project(':hibernate-core')
}

tasks {
	pluginUnderTestMetadata {
		pluginClasspath.from configurations.additionalPluginTestClasspath
	}
}
But still end up with test failures because:
Copy code
> Could not find org.hibernate.orm:hibernate-core:6.1.3-SNAPSHOT.
t
Oh, indeed it doesn't work that way. If you already have the dependency in implementation, then it's already in the "plugin classpath". But that only means you can resolve plugin IDs from it, or use classes from the build scripts.
s
That is what I was asking πŸ˜‰
I guess I worded it unclearly
t
If you want to resolve JARs from your build, from the build driven by TestKit, then you could use a composite build (emit a settings.gradle with includeBuild)
s
You'd still need to publish it somewhere first, no?
That seems to be the essential limitation of TestKit here
t
No. Imagine, without TestKit, having to resolve Hibernate right from your other Hibernate project, but from another unrelated project; then you can use a composite build so you don't even have to "publish" a "snapshot". https://docs.gradle.org/current/userguide/composite_builds.html Now, that other unrelated project can be driven by TestKit, it won't change anything πŸ˜‰ (assuming the included build is compatible with the version of Gradle you're using for TestKit's withGradleVersion ; otherwise you'll indeed have to publish somewhere)
s
I understand what composite builds are. We use them already
Just not groking how that helps here
t
Then either you don't understand what I'm suggesting, or I don't understand what your problem is / what you're trying to do πŸ˜…
s
Um, sure. That's why I said "I don't understanbd" πŸ˜‰
I do in fact understand what the problem is - TestKit cannot locally resolve other local modules
I do not understand what you are suggesting then I guess
t
How/where do you reference those modules? in
dependencies {}
of the build driven by TestKit?
s
I have a main module named
hibernate-core
I also have a plugin that exposes some functionality of
hibernate-core
which it therefore needs as an implementation detail
The "test" project (aka user project mock) applies the plugin, but it also itself has a dependency on
hibernate-core
. That project is defined as:
Copy code
plugins {
    id 'java'
    id 'org.hibernate.orm'
}

dependencies {
    implementation 'org.hibernate.orm:hibernate-core:6.1.0.Final'
}

hibernate {
    // DSL block
}
As you can see, the test project "cheats" and uses a published version. No problem, Gradle isolates classpaths
This really is isolated to TestKit
t
This should work, provided you also have a
repository {}
the resolve the dependency from.
s
The project itself is fine. What does not work is the "local resolution" of
hibernate-core
relative to
id 'org.hibernate.orm'
Notice the error message... it is not complaining about resolving the
.Final
reference. It is complaining about resolving a
SNAPSHOT
reference
t
Isn't that because your plugin itself adds a dependency on hibernate-core using that SNAPSHOT version?
s
πŸ™‚
square meet one
Yes, that is in fact the exact problem
Anyway, this all just reinforces that TestKit does not support this
And I'll have to use a solution like Javi mentioned
t
If you wanted that to work, then you could have that "test" project itself be a composite build with the "outer" project, so it would resolve hibernate-core from that project (and if using the same Gradle version et al. almost all tasks should be up-to-date)
…or publish to an intermediary directory that you then use as a maven repository from the "test projet".
s
You mean separate the plugin and its tests?
t
Not necessarily no.
Make the "mock" project itself a composite build with your own project that you are currently building / running tests.
s
The "mock" project is the test
So you are saying no, but meaning yes I think
I'd be happy to be proven wrong though - https://github.com/hibernate/hibernate-orm
t
I'm certain I already saw such a setup in an open source project, but cannot remember which one. Have the mock project have a settings.gradle file that includeBuild() the Hibernate root project (so you have Hibernate inside your Hibernate)
s
So you are saying that that test (mock) project needs to be moved out of the plugin project, effectively splitting the plugin from it its tests
t
Nope: just have the settings.gradle be generated dynamically with the appropriate path to the Hibernate project (the one for which tests are running)
s
That will only work if you move the test (mock) outside the plugin
t
Hmm no. Why would it be?
s
Sure, I'll try that
t
For example, put the following in the test settings.gradle:
Copy code
includeBuild(System.getProperty("test.hibernate-project-path"))
and add the following to TestKit's `withArguments()`:
"-Dtest.hibernate-project-path=" + Path.of("../../").toAbsolutePath()
s
To make sure I understand your suggestion properly... you think I should: 1. Change the test's settings.gradle to use
includeBuild
with relative path up-to
hibernate-core
2. Change the test's project.gradle to use
implementation project('hibernate-core')
3. 3. Do the `pluginClasspath.from`stuff you mentioned earlier correct?
No need for all that... the relative path is consistent
So I have:
Copy code
includeBuild "../../../../../../hibernate-core"
That's what you suggest right?
But it does not like that, though the error is strange
Copy code
org.gradle.api.InvalidUserDataException: A path must be specified!
Though clearly a path is specified
The stacktrace shows it is trying to resolve the included build btw
t
Are you sure about that path? when I run the tests locally, it puts the test project inside /tmp/junitSomething/ so the includeBuild needs to reference the project with an absolute path
(I don't have failures without making any change though, so impossible to tell if my proposed changes (https://gradle-community.slack.com/archives/CA745PZHN/p1665751862754669?thread_ts=1665747599.506999&cid=CA745PZHN) have any effect; except that they don't fail the build either)
s
Ah, right, it gets copied
You need to comment out :
Copy code
//    useSameVersion = false
That effectively forces the test to use the published version. Aka, its not testing anything
t
Copy code
diff --git a/tooling/hibernate-gradle-plugin/src/test/resources/projects/simple/build.gradle b/tooling/hibernate-gradle-plugin/src/test/resources/projects/simple/build.gradle
index 20bc5d3..1f34c4b 100644
--- a/tooling/hibernate-gradle-plugin/src/test/resources/projects/simple/build.gradle
+++ b/tooling/hibernate-gradle-plugin/src/test/resources/projects/simple/build.gradle
@@ -27,7 +27,7 @@ dependencies {
 hibernate {
     // to get using the same version to work, we'd have to install hibernate-core into maven local prior to running these.
     // suck we won't be able to adequately test this part, but
-    useSameVersion = false
+    // useSameVersion = false
     enhancement {
         lazyInitialization( true )
         dirtyTracking = true
Copy code
diff --git a/tooling/hibernate-gradle-plugin/src/test/resources/projects/simple/settings.gradle b/tooling/hibernate-gradle-plugin/src/test/resources/projects/simple/settings.gradle
index e69de29..e823638 100644
--- a/tooling/hibernate-gradle-plugin/src/test/resources/projects/simple/settings.gradle
+++ b/tooling/hibernate-gradle-plugin/src/test/resources/projects/simple/settings.gradle
@@ -0,0 +1 @@
+includeBuild(System.getProperty("test.hibernate-project-path"))
Copy code
diff --git a/tooling/hibernate-gradle-plugin/src/test/java/org/hibernate/orm/tooling/gradle/JavaProjectTests.java b/tooling/hibernate-gradle-plugin/src/test/java/org/hibernate/orm/tooling/gradle/JavaProjectTests
.java
index 16b07d2..b5d5903 100644
--- a/tooling/hibernate-gradle-plugin/src/test/java/org/hibernate/orm/tooling/gradle/JavaProjectTests.java
+++ b/tooling/hibernate-gradle-plugin/src/test/java/org/hibernate/orm/tooling/gradle/JavaProjectTests.java
@@ -36,7 +36,7 @@ class JavaProjectTests {
                                .withProjectDir( projectDir.toFile() )
                                .withPluginClasspath()
                                .withDebug( true )
-                               .withArguments( "clean", "compileJava", "--stacktrace", "--no-build-cache" )
+                               .withArguments( "clean", "compileJava", "--stacktrace", "--no-build-cache", "-Dtest.hibernate-project-path=" + Path.of("../../").toAbsolutePath() )
                                .forwardOutput();
(repeat last change for each
withArguments()
, repeat changes for Kotlin tests)
Copy code
BUILD SUCCESSFUL in 56s
21 actionable tasks: 2 executed, 19 up-to-date
s
Got pulled into one of those awesome "all Friday afternoon" meetings πŸ˜‰ I'll play around with this some more. Thanks everyone