Skip to content

Commit 8a4a538

Browse files
authored
The Service registry Maven plugin must use runtime dependencies when generating the ApplicationBinding, as otherwise the services from them are not "seen" by the runtime. (helidon-io#9868)
Example: helidon-config-yaml in runtime scope will not be used at all when using generated binding.
1 parent 5c31530 commit 8a4a538

File tree

4 files changed

+12
-5
lines changed

4 files changed

+12
-5
lines changed

docs/src/main/asciidoc/se/injection.adoc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -835,6 +835,10 @@ annotation (i.e. `start(ApplicationBinding.create())`)
835835
- `start(Binding, ServiceRegistryConfig)` - same as above, allows for customization of configuration,
836836
if used, remember to set discovery to `false` to prevent automated discovery from the classpath
837837
838+
Application binding contains reference to all services that can be used by the application at runtime. As a result,
839+
when using the generated binding and JPMS (`module-info.java`), all modules that contain services (or Java ServiceLoader providers used by the registry) must be configured as `required` in the module info, otherwise
840+
the binding cannot be compiled.
841+
838842
All options to start a Helidon application that uses service registry:
839843
// Can be commented out once the PR https://github.com/helidon-io/helidon/pull/9840 is merged
840844
// - A custom Main method using `ServiceRegistryManager.start(...)` methods, or `ServiceRegistryManager.create(...)` methods

service/maven-plugin/src/main/java/io/helidon/service/maven/plugin/CreateApplicationAbstractMojo.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -379,11 +379,12 @@ String javaRelease() {
379379
}
380380

381381
LinkedHashSet<Path> getSourceClasspathElements() {
382+
// the application biding must use runtime classpath
382383
MavenProject project = mavenProject();
383-
LinkedHashSet<Path> result = new LinkedHashSet<>(project.getCompileArtifacts().size());
384+
LinkedHashSet<Path> result = new LinkedHashSet<>();
384385
result.add(Paths.get(project.getBuild().getOutputDirectory()));
385-
for (Object a : project.getCompileArtifacts()) {
386-
result.add(((Artifact) a).getFile().toPath());
386+
for (Object dependency : project.getRuntimeArtifacts()) {
387+
result.add(((Artifact) dependency).getFile().toPath());
387388
}
388389
return result;
389390
}

service/maven-plugin/src/main/java/io/helidon/service/maven/plugin/CreateApplicationMojo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
@Mojo(name = "create-application",
3535
defaultPhase = LifecyclePhase.COMPILE,
3636
threadSafe = true,
37-
requiresDependencyResolution = ResolutionScope.COMPILE)
37+
requiresDependencyResolution = ResolutionScope.RUNTIME)
3838
public class CreateApplicationMojo extends CreateApplicationAbstractMojo {
3939

4040
/**

service/maven-plugin/src/main/java/io/helidon/service/maven/plugin/CreateTestApplicationMojo.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@
3535
* A mojo wrapper to {@link BindingGenerator} for test specific types.
3636
* For test scope, we only generate binding, as main class would not be useful.
3737
*/
38-
@Mojo(name = "test-application-create", defaultPhase = LifecyclePhase.TEST_COMPILE, threadSafe = true,
38+
@Mojo(name = "test-application-create",
39+
defaultPhase = LifecyclePhase.TEST_COMPILE,
40+
threadSafe = true,
3941
requiresDependencyResolution = ResolutionScope.TEST)
4042
@SuppressWarnings("unused")
4143
public class CreateTestApplicationMojo extends CreateApplicationAbstractMojo {

0 commit comments

Comments
 (0)