Skip to content

Commit 3f74e8b

Browse files
authored
fix: include filesystem dependencies in gradle plugin class finder (#19287)
Gradle plugin builds a class finder upon the JAR files obtained through the project dependencies resolved artifacts, that however does not include filesystem dependencies. This change adds filesystem dependencis to the list of project JAR files provided to the class finder. Fixes #19024
1 parent 2f08856 commit 3f74e8b

3 files changed

Lines changed: 78 additions & 1 deletion

File tree

‎flow-plugins/flow-gradle-plugin/src/functionalTest/kotlin/com/vaadin/gradle/VaadinSmokeTest.kt‎

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,76 @@ class VaadinSmokeTest : AbstractGradleTest() {
369369

370370
}
371371

372+
/**
373+
* Tests that build works with resources from classpath, not only from
374+
* frontend directory
375+
*
376+
* https://github.com/vaadin/flow/issues/14420
377+
*/
378+
@Test
379+
fun vaadinBuildFrontendShouldScanFilesystemDependencies() {
380+
testProject.buildFile.writeText(
381+
"""
382+
plugins {
383+
id 'war'
384+
id 'com.vaadin'
385+
}
386+
repositories {
387+
mavenLocal()
388+
mavenCentral()
389+
maven { url = 'https://maven.vaadin.com/vaadin-prereleases' }
390+
}
391+
dependencies {
392+
implementation("com.vaadin:flow:$flowVersion")
393+
implementation(files('libs/addon.jar'))
394+
}
395+
"""
396+
)
397+
398+
testProject.newFile(
399+
"src/main/java/org/vaadin/example/MainView.java", """
400+
package org.vaadin.example;
401+
402+
import com.vaadin.flow.component.html.Div;
403+
import com.vaadin.flow.component.html.Span;
404+
import com.vaadin.flow.router.Route;
405+
import com.vaadin.example.Addon;
406+
407+
@Route("")
408+
public class MainView extends Div {
409+
410+
public MainView() {
411+
add(new Addon());
412+
}
413+
}
414+
""".trimIndent()
415+
)
416+
417+
testProject.newFolder("libs")
418+
val addonJar: File = testProject.newFile("libs/addon.jar")
419+
Files.copy(
420+
File(javaClass.classLoader.getResource("addon.jar").path).toPath(),
421+
addonJar.toPath(), StandardCopyOption.REPLACE_EXISTING
422+
)
423+
424+
val result: BuildResult = testProject.build("-Pvaadin.productionMode", "build")
425+
result.expectTaskSucceded("vaadinPrepareFrontend")
426+
result.expectTaskSucceded("vaadinBuildFrontend")
427+
428+
val addonFile =
429+
File(testProject.dir, FrontendUtils.DEFAULT_PROJECT_FRONTEND_GENERATED_DIR + "jar-resources/my-addon.js")
430+
expect(true, addonFile.toString()) { addonFile.exists() }
431+
432+
val importsFile = File(
433+
testProject.dir,
434+
FrontendUtils.DEFAULT_PROJECT_FRONTEND_GENERATED_DIR + "flow/" + FrontendUtils.IMPORTS_NAME
435+
)
436+
expect(true, importsFile.toString()) { importsFile.exists() }
437+
expect(true, "Addon javascript should be found and imported") {
438+
importsFile.readText().contains("import 'Frontend/generated/jar-resources/my-addon.js'")
439+
}
440+
}
441+
372442
@Test
373443
fun pluginShouldFailWithUnsupportedGradleVersion() {
374444

Binary file not shown.

‎flow-plugins/flow-gradle-plugin/src/main/kotlin/com/vaadin/gradle/GradlePluginAdapter.kt‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,16 @@ internal class GradlePluginAdapter(
4747
val dependencyConfigurationJars: List<File> = if (dependencyConfiguration != null) {
4848
var artifacts: List<ResolvedArtifact> =
4949
dependencyConfiguration.resolvedConfiguration.resolvedArtifacts.toList()
50+
51+
// Detect local filesystem dependencies that are not resolved as artifacts
52+
// They will be added to the filtered artifacts list
53+
val filesystemDependencies =
54+
dependencyConfiguration.resolvedConfiguration.files.minus(artifacts.map { it.file }.toSet())
55+
5056
val artifactFilter = config.classpathFilter.toPredicate()
5157
artifacts = artifacts.filter { artifactFilter.test(it.moduleVersion.id.module) }
52-
artifacts.map { it.file }
58+
59+
artifacts.map { it.file }.plus(filesystemDependencies)
5360
} else listOf()
5461

5562
// we need to also analyze the project's classes

0 commit comments

Comments
 (0)