-
Notifications
You must be signed in to change notification settings - Fork 48
Switch both call sites from dynamic property access to NamedDomainObjectCollection.findByName(), which returns null safely, and fall back to conventional default paths when the java plugin is absent #1093
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
venmanyarun
merged 5 commits into
OpenLiberty:main
from
venmanyarun:libertydev_sourceset_issue
Jul 8, 2026
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
51d9c00
Switch both call sites from dynamic property access to NamedDomainObj…
venmanyarun b6533fc
updated default directory mapping to work with sourcesets
venmanyarun 0afb949
Fix sourceSets dynamic access in DeployTask and GenerateFeaturesTask
venmanyarun 9c62128
Added SourceSet tests for Dev Mode and Deploy Task
venmanyarun e86658c
changing sourceSet path in tests
venmanyarun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
131 changes: 131 additions & 0 deletions
131
src/test/groovy/io/openliberty/tools/gradle/TestMultiModuleEarNoJavaPluginDevMode.groovy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,131 @@ | ||
| /* | ||
| * (C) Copyright IBM Corporation 2026. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package io.openliberty.tools.gradle | ||
|
|
||
| import org.junit.AfterClass | ||
| import org.junit.BeforeClass | ||
| import org.junit.Test | ||
|
|
||
| import static org.junit.Assert.assertTrue | ||
|
|
||
| /** | ||
| * Integration test for the fix to: | ||
| * "Could not get unknown property 'main' for SourceSet container" | ||
| * | ||
| * Reproduces the exact user scenario: an EAR submodule that applies ONLY | ||
| * 'ear' + 'liberty' plugins (no 'java' plugin), while WAR and JAR submodules | ||
| * each apply 'java' themselves. | ||
| * | ||
| * Prior to the fix, DevTask.groovy accessed project.sourceSets.main using | ||
| * Groovy dynamic property syntax, which throws on Gradle 9 when the 'java' | ||
| * plugin is not applied (so 'main' source set does not exist). | ||
| * | ||
| * The fix switches to sourceSets.findByName('main') / findByName('test'), | ||
| * which returns null safely, and falls back to conventional default paths. | ||
| * | ||
| * This test verifies that libertyDev starts successfully on such a project | ||
| * and that hot-recompilation of a JAR module Java file still works. | ||
| */ | ||
| class TestMultiModuleEarNoJavaPluginDevMode extends BaseDevTest { | ||
|
|
||
| static File resourceDir = new File("build/resources/test/multi-module-loose-ear-no-java-plugin-test") | ||
| static File buildDir = new File(integTestDir, "/multi-module-loose-ear-no-java-plugin-test") | ||
| static String buildFilename = "build.gradle" | ||
|
|
||
| @BeforeClass | ||
| static void setup() throws IOException, InterruptedException, FileNotFoundException { | ||
| createDir(buildDir) | ||
| createTestProject(buildDir, resourceDir, buildFilename) | ||
| new File(buildDir, "build").mkdirs() | ||
|
|
||
| // Start libertyDev with --skipTests so we don't need test infrastructure. | ||
| // This exercises the fixed code path in DevTask.action() and | ||
| // DevTask.getProjectModules() for an EAR project without 'java' plugin. | ||
| runDevMode("--skipTests", buildDir) | ||
| } | ||
|
|
||
| /** | ||
| * Primary regression test: libertyDev must start without throwing | ||
| * "Could not get unknown property 'main' for SourceSet container" | ||
| * | ||
| * If the bug is present, setup() would have failed with a BuildException | ||
| * before this test even runs. The fact that the server reached dev mode | ||
| * proves the fix is effective. | ||
| */ | ||
| @Test | ||
| void earModuleWithoutJavaPluginStartsDevMode() throws Exception { | ||
| // Server startup is verified in setup() via verifyLogMessage("Liberty is running in dev mode."). | ||
| // This test documents the intent and provides a named regression marker. | ||
| assertTrue("libertyDev should be running in dev mode", | ||
| verifyLogMessage(5000, "Liberty is running in dev mode.")) | ||
| } | ||
|
|
||
| /** | ||
| * Verify that modifying a Java source file in the JAR submodule | ||
| * (which DOES have the 'java' plugin) triggers recompilation while | ||
| * the EAR module's absence of sourceSets.main does not cause a crash. | ||
| */ | ||
| @Test | ||
| void modifyJavaFileInJarSubmoduleTriggersRecompilation() throws Exception { | ||
| File srcGreeter = new File(buildDir, | ||
| "jar/src/main/java/io/openliberty/guides/multimodules/lib/Greeter.java") | ||
| File targetGreeter = new File(buildDir, | ||
| "jar/build/classes/java/main/io/openliberty/guides/multimodules/lib/Greeter.class") | ||
|
|
||
| assertTrue("Greeter.java source file must exist", srcGreeter.exists()) | ||
| assertTrue("Greeter.class must exist after initial build", targetGreeter.exists()) | ||
|
|
||
| long lastModified = targetGreeter.lastModified() | ||
| waitLongEnough() | ||
|
|
||
| // Append a no-op comment to trigger the file watcher | ||
| BufferedWriter javaWriter = new BufferedWriter(new FileWriter(srcGreeter, true)) | ||
| javaWriter.append(" // recompile trigger") | ||
| javaWriter.close() | ||
|
|
||
| assertTrue("Greeter.class should be recompiled after source change", | ||
| waitForCompilation(targetGreeter, lastModified, 12000)) | ||
| } | ||
|
|
||
| /** | ||
| * Verify that modifying the EAR build.gradle triggers the expected | ||
| * "change detected in build file" dev mode warning. | ||
| */ | ||
| @Test | ||
| void modifyEarBuildGradleTriggersWarning() throws Exception { | ||
| waitLongEnough() | ||
|
|
||
| File earBuildGradle = new File(buildDir, "ear/build.gradle") | ||
| assertTrue("ear/build.gradle must exist", earBuildGradle.exists()) | ||
|
|
||
| BufferedWriter buildWriter = new BufferedWriter(new FileWriter(earBuildGradle, true)) | ||
| buildWriter.append(" // testing") | ||
| buildWriter.close() | ||
|
|
||
| assertTrue("Expected build file change warning in dev mode output", | ||
| verifyLogMessage(12000, | ||
| "A change was detected in a build file. The libertyDev task could not determine if a server restart is required. To restart server, type 'r' and press Enter.")) | ||
| } | ||
|
|
||
| @AfterClass | ||
| static void cleanUpAfterClass() throws Exception { | ||
| String stdout = getContents(logFile, "Dev mode std output") | ||
| System.out.println(stdout) | ||
| String stderr = getContents(errFile, "Dev mode std error") | ||
| System.out.println(stderr) | ||
| cleanUpAfterClass(true) | ||
| } | ||
| } |
17 changes: 17 additions & 0 deletions
17
src/test/resources/multi-module-loose-ear-no-java-plugin-test/build.gradle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| allprojects { | ||
| group = 'io.openliberty.guides' | ||
| version = '1.0-SNAPSHOT' | ||
| } | ||
|
|
||
| // Intentionally NOT applying the 'java' plugin to all subprojects here. | ||
| // The 'ear' submodule only has 'ear' + 'liberty' plugins applied. | ||
| // This reproduces the user scenario that caused: | ||
| // "Could not get unknown property 'main' for SourceSet container" | ||
| // The fix in DevTask.groovy uses sourceSets.findByName('main') which | ||
| // returns null instead of throwing when 'java' is not applied. | ||
| subprojects { | ||
| repositories { | ||
| mavenLocal() | ||
| mavenCentral() | ||
| } | ||
| } |
52 changes: 52 additions & 0 deletions
52
src/test/resources/multi-module-loose-ear-no-java-plugin-test/ear/build.gradle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| // | ||
| // This EAR module intentionally applies ONLY 'ear' and 'liberty' plugins — | ||
| // no 'java' plugin is applied here or from the root build.gradle. | ||
| // This reproduces the exact user scenario that triggered: | ||
| // "Could not get unknown property 'main' for SourceSet container" | ||
| // when running 'libertyDev' on Gradle 9 with liberty-gradle-plugin 4.x. | ||
| // | ||
| apply plugin: 'ear' | ||
| apply plugin: 'liberty' | ||
|
|
||
| description = 'EAR Module' | ||
|
|
||
| buildscript { | ||
| repositories { | ||
| mavenLocal() | ||
| mavenCentral() | ||
| maven { | ||
| url = 'https://central.sonatype.com/repository/maven-snapshots/' | ||
| } | ||
| } | ||
| dependencies { | ||
| classpath "io.openliberty.tools:liberty-gradle-plugin:$lgpVersion" | ||
| } | ||
| } | ||
|
|
||
| dependencies { | ||
| deploy project(path: ':war', configuration: 'warOnly') | ||
| deploy project(path: ':jar', configuration: 'jarOnly') | ||
| libertyRuntime group: runtimeGroup, name: kernelArtifactId, version: runtimeVersion | ||
| } | ||
|
|
||
| ear { | ||
| archiveFileName = rootProject.name + "-" + getArchiveBaseName().get() + "-" + rootProject.version + '.' + getArchiveExtension().get() | ||
| deploymentDescriptor { | ||
| webModule('ejb-war-1.0-SNAPSHOT.war', '/converter') | ||
| } | ||
| } | ||
|
|
||
| liberty { | ||
| server { | ||
| name = "ejbServer" | ||
| deploy { | ||
| apps = [ear] | ||
| copyLibsDirectory = file("${project.getLayout().getBuildDirectory().getAsFile().get()}/copy/libs") | ||
| } | ||
| verifyAppStartTimeout = 30 | ||
| looseApplication = true | ||
| } | ||
| } | ||
|
|
||
| deploy.dependsOn 'ear' | ||
| ear.dependsOn ':jar:jar', ':war:war' |
1 change: 1 addition & 0 deletions
1
...sources/multi-module-loose-ear-no-java-plugin-test/ear/src/main/liberty/config/server.env
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| WLP_LOGGING_CONSOLE_LOGLEVEL=INFO |
17 changes: 17 additions & 0 deletions
17
...sources/multi-module-loose-ear-no-java-plugin-test/ear/src/main/liberty/config/server.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| <server description="Sample Liberty server"> | ||
|
|
||
| <featureManager> | ||
| <feature>servlet-4.0</feature> | ||
| </featureManager> | ||
|
|
||
| <variable name="http.port" defaultValue="9082" /> | ||
| <variable name="https.port" defaultValue="9447" /> | ||
|
|
||
| <httpEndpoint host="*" httpPort="${http.port}" | ||
| httpsPort="${https.port}" id="defaultHttpEndpoint" /> | ||
|
|
||
| <enterpriseApplication id="ejb-ear-1.0-SNAPSHOT" | ||
| location="ejb-ear-1.0-SNAPSHOT.ear" | ||
| name="ejb-ear-1.0-SNAPSHOT"> | ||
| </enterpriseApplication> | ||
| </server> |
29 changes: 29 additions & 0 deletions
29
src/test/resources/multi-module-loose-ear-no-java-plugin-test/jar/build.gradle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
|
|
||
| apply plugin: 'java' | ||
|
|
||
| description = 'JAR Module' | ||
|
|
||
| java { | ||
| sourceCompatibility = JavaVersion.VERSION_1_8 | ||
| targetCompatibility = JavaVersion.VERSION_1_8 | ||
| } | ||
| tasks.withType(JavaCompile).configureEach { | ||
| options.encoding = 'UTF-8' | ||
| } | ||
|
|
||
| dependencies { | ||
| testImplementation 'org.junit.jupiter:junit-jupiter:5.11.0' | ||
| } | ||
|
|
||
| // Create a custom configuration that only includes the JAR artifact | ||
| configurations { | ||
| jarOnly | ||
| } | ||
|
|
||
| artifacts { | ||
| jarOnly jar | ||
| } | ||
|
|
||
| jar { | ||
| archiveFileName = rootProject.name + "-" + getArchiveBaseName().get() + "-" + rootProject.version + '.' + getArchiveExtension().get() | ||
| } |
8 changes: 8 additions & 0 deletions
8
...no-java-plugin-test/jar/src/main/java/io/openliberty/guides/multimodules/lib/Greeter.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| package io.openliberty.guides.multimodules.lib; | ||
|
|
||
| public class Greeter { | ||
|
|
||
| public static String greet(String name) { | ||
| return "Hello, " + name + "!"; | ||
| } | ||
| } |
8 changes: 8 additions & 0 deletions
8
src/test/resources/multi-module-loose-ear-no-java-plugin-test/settings.gradle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| rootProject.name = 'ejb' | ||
| include ':jar' | ||
| include ':war' | ||
| include ':ear' | ||
|
|
||
| project(':jar').projectDir = "$rootDir/jar" as File | ||
| project(':war').projectDir = "$rootDir/war" as File | ||
| project(':ear').projectDir = "$rootDir/ear" as File |
34 changes: 34 additions & 0 deletions
34
src/test/resources/multi-module-loose-ear-no-java-plugin-test/war/build.gradle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
|
|
||
| apply plugin: 'java' | ||
| apply plugin: 'war' | ||
|
|
||
| description = 'WAR Module' | ||
|
|
||
| java { | ||
| sourceCompatibility = JavaVersion.VERSION_1_8 | ||
| targetCompatibility = JavaVersion.VERSION_1_8 | ||
| } | ||
| tasks.withType(JavaCompile).configureEach { | ||
| options.encoding = 'UTF-8' | ||
| } | ||
|
|
||
| dependencies { | ||
| testImplementation 'org.junit.jupiter:junit-jupiter:5.11.0' | ||
| compileOnly 'javax.servlet:javax.servlet-api:4.0.1' | ||
| implementation project(path: ':jar', configuration: 'jarOnly') | ||
| } | ||
|
|
||
| // Create a custom configuration that only includes the WAR artifact | ||
| configurations { | ||
| warOnly | ||
| } | ||
|
|
||
| artifacts { | ||
| warOnly war | ||
| } | ||
|
|
||
| war { | ||
| archiveFileName = rootProject.name + "-" + getArchiveBaseName().get() + "-" + rootProject.version + '.' + getArchiveExtension().get() | ||
| } | ||
|
|
||
| war.dependsOn ':jar:jar' |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.