Hari Venkata Ramana Addepalli
09/18/2024, 10:01 AMCaleb Cushing
09/18/2024, 7:07 PMHari Venkata Ramana Addepalli
09/19/2024, 2:38 PMCaleb Cushing
09/19/2024, 2:41 PMCaleb Cushing
09/19/2024, 2:42 PMHari Venkata Ramana Addepalli
09/19/2024, 2:48 PMCaleb Cushing
09/19/2024, 2:51 PMHari Venkata Ramana Addepalli
09/19/2024, 3:24 PMCaleb Cushing
09/19/2024, 3:31 PMCaleb Cushing
09/19/2024, 3:33 PMtest-fixtures plugin and then create src/testFixtures/java/A/B... and move your abstract class to the appropriate packageCaleb Cushing
09/19/2024, 3:35 PMtestFixtureImplementation("org.example:foo")Caleb Cushing
09/19/2024, 3:36 PMtestImplementation(testFixture(project(":Y"))) I think it isCaleb Cushing
09/19/2024, 3:37 PMtestImplementation(testFixture(project)), that all make sense?Hari Venkata Ramana Addepalli
09/19/2024, 3:42 PMCaleb Cushing
09/19/2024, 3:43 PMtestFixtures the same as you would main and test directories, it's just another sourceSetCaleb Cushing
09/19/2024, 3:46 PMCaleb Cushing
09/19/2024, 3:47 PMCaleb Cushing
09/19/2024, 3:47 PMHari Venkata Ramana Addepalli
09/19/2024, 3:49 PMHari Venkata Ramana Addepalli
09/19/2024, 3:49 PMCaleb Cushing
09/19/2024, 3:49 PMCaleb Cushing
09/19/2024, 3:50 PMCaleb Cushing
09/19/2024, 3:51 PMCaleb Cushing
09/19/2024, 3:51 PMCaleb Cushing
09/20/2024, 5:50 PMVampire
09/20/2024, 6:47 PMsrcDirs declarations look very fishy anyway.
It looks like you have some tasks that generate code and there configure the paths to their outputs and then adding explicit dependsOn for some of the tasks needing sources.
This is not really a good idea. Instead you should make sure the generation tasks do properly declare their inputs and outputs (as always) and then configure those tasks directly as srcDir which makes their outputs considered sources and automatically adds an implicit task dependency to all tasks that need source files, including compilation tasks, javadoc tasks, source jar tasks, static code analyzers, .....
Practically any explicit dependsOn that does not have a lifecycle task on the left-hand side is a code smell and usually a sign of not wiring outputs and inputs together properly.
But having said all that, I agree to what Caleb said.
test fixtures are for "things" you want to share to other projects for their tests, whether this are actual "fixtures", or data generators, or base test classes, doesn't matter.
Regarding the question what changed between 5.1 and 7.4.2, nothing. "testImplementation project("<reference to base class project>"") also in 5.1 does not mean that Z/test can use Y/test, but only the Z/test can use Y/main. Maybe there were more things you do not mention that you changed during the upgrade and makes it not work anymore or something like that. For example look at this simple MCVE which does not compile as ZTest does not see `YTest`:
./gradle/wrapper/gradle-wrapper.properties
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
./settings.gradle.kts
rootProject.name = "A"
include("Y")
include("Z")
./Y/build.gradle.kts
plugins {
java
}
./Y/src/test/java/y/YTest.java
package y;
public class YTest {
}
./Z/build.gradle.kts
plugins {
java
}
dependencies {
testImplementation(project(":Y"))
}
./Z/src/test/java/z/ZTest.java
package z;
import y.YTest;
public class ZTest {
public YTest ytest;
}
If you want to use classes from Y/test in Z/test, usually the best idea is what Caleb said, to instead put them to Y/testFixtures and depen on that from Z/test. If for whatever reason this does not work out but it must be the Y/test source set you share, then also as Caleb said, you should declare a feature variant based on the Y/test source set as per the linked documentation. This is just not there by default, as the test source set is meant for testing the main source set in the same project and not for providing test utilities for other projects, for which testFixutres are intended.Vampire
09/20/2024, 6:54 PMCaleb Cushing
09/20/2024, 7:03 PM@SpringBootApplication . Since this class has no specific dependencies on any of my other projects, I have simply put it in its own subproject. A test fixture should probably need to sit between main and the test suite always. Not being desirable in main, but being useful in more than one of your test suites.
2. the second thing I'd say is whether or not it's a final test class... meaning not a base class but something that junit, or likewise would actually execute by itself. That would feel like it needs refactoring or at least to live in a feature variant by another name.
neither of these sound like the case here, so I'll say you're fine on that front.