Skip to content
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

Allow to filter dependencies in multi-build mode #16600

Merged
merged 1 commit into from
Apr 19, 2021

Conversation

essobedo
Copy link
Contributor

cc @bcournaud

fixes #16599

Motivation

Thanks to #16053, it is now possible to build several artifacts from one module but it is not yet possible to have a way to filter out some dependencies such that we could end up with artifacts containing useless dependencies. The idea of this feature is to go a little bit further by proposing a way to filter out the dependencies.

Modifications:

  • Adds the parameter optionalDependencies to the class PackageConfig in order to specify the list of optional dependencies that we would like to include into the final package of the application.
  • Adds the parameter filterOptionalDependencies to the class PackageConfig to enable or not the feature, it is disabled by default for backward compatibility reasons.
  • Adds the field optionalDependencies to the class OutputTargetBuildItem corresponding to the parameter optionalDependencies but after being post processed to make it absent if the feature is disabled, to make it empty if no optional dependencies were specified and to convert the String representation of the artifacts into the corresponding AppArtifactKey's instances
  • Relies on the field optionalDependencies of the class OutputTargetBuildItem to filter out all the dependencies of the application that have been marked as optional for all supported package types.
  • Adapts the integration test for the multi-build to test this feature for all supported package types (but native one) by adding two optional dependencies to the project and filtering them out using different parameters.

Result

It is now possible to build several artifacts with specific dependencies, this could be used for example to package the same application for different databases.

@essobedo
Copy link
Contributor Author

@famod

I'm wondering if that could be used to build for multiple databases, given that you cannot differentiate dependencies with this approach (but you could with profiles).

This PR should do the job

cc @aloubyansky

@essobedo essobedo force-pushed the 16599/filter-dependencies branch from 520188e to 145c883 Compare April 17, 2021 06:39
@quarkus-bot
Copy link

quarkus-bot bot commented Apr 17, 2021

This workflow status is outdated as a new workflow run has been triggered.

🚫 This workflow run has been cancelled.

Failing Jobs - Building 520188e

Status Name Step Test failures Logs Raw logs
Initial JDK 11 Build Build ⚠️ Check → Logs Raw logs
🚫 Devtools Tests - JDK ${{ matrix.java.name }}
🚫 Devtools Tests - JDK 11 Windows
🚫 Gradle Tests - JDK 11 ${{ matrix.os.family }}
🚫 JVM Tests - JDK ${{ matrix.java.name }}
🚫 JVM Tests - JDK 11 Windows
🚫 Maven Tests - JDK ${{ matrix.java.name }}
🚫 Maven Tests - JDK 11 Windows
🚫 MicroProfile TCKs Tests
🚫 Native Tests - ${{ matrix.category }}
🚫 Native Tests - Windows - ${{ matrix.category }}

@aloubyansky
Copy link
Member

@essobedo is the only reason Maven profiles wouldn't work here because you want to activate both build configs during the same maven build?

@essobedo
Copy link
Contributor Author

essobedo commented Apr 17, 2021

@essobedo is the only reason Maven profiles wouldn't work here because you want to activate both build configs during the same maven build?

@aloubyansky Exactly, with those changes, we can for example build the application for different databases with the same maven build

@essobedo essobedo force-pushed the 16599/filter-dependencies branch 2 times, most recently from fb69c21 to 4795a69 Compare April 18, 2021 09:14
@quarkus-bot
Copy link

quarkus-bot bot commented Apr 18, 2021

This workflow status is outdated as a new workflow run has been triggered.

🚫 This workflow run has been cancelled.

Failing Jobs - Building fb69c21

Status Name Step Test failures Logs Raw logs
Initial JDK 11 Build Build ⚠️ Check → Logs Raw logs
🚫 Devtools Tests - JDK ${{ matrix.java.name }}
🚫 Devtools Tests - JDK 11 Windows
🚫 Gradle Tests - JDK 11 ${{ matrix.os.family }}
🚫 JVM Tests - JDK ${{ matrix.java.name }}
🚫 JVM Tests - JDK 11 Windows
🚫 Maven Tests - JDK ${{ matrix.java.name }}
🚫 Maven Tests - JDK 11 Windows
🚫 MicroProfile TCKs Tests
🚫 Native Tests - ${{ matrix.category }}
🚫 Native Tests - Windows - ${{ matrix.category }}

@quarkus-bot
Copy link

quarkus-bot bot commented Apr 18, 2021

This workflow status is outdated as a new workflow run has been triggered.

Failing Jobs - Building 4795a69

Status Name Step Test failures Logs Raw logs
✔️ JVM Tests - JDK 11
JVM Tests - JDK 15 Build Test failures Logs Raw logs

Full information is available in the Build summary check run.

Test Failures

⚙️ JVM Tests - JDK 15 #

📦 integration-tests/artemis-core

io.quarkus.it.artemis.ArtemisProducerTest.test - More details - Source on GitHub

📦 integration-tests/artemis-jms

io.quarkus.it.artemis.ArtemisProducerTest.test - More details - Source on GitHub

📦 integration-tests/bootstrap-config/application

io.quarkus.it.bootstrap.config.GreetingResourceTest.testEndpoint - More details - Source on GitHub

📦 integration-tests/cache

io.quarkus.it.cache.TreeTestCase.test - More details - Source on GitHub

📦 integration-tests/consul-config

io.quarkus.it.consul.config.GreetingResourceTest.testGreeting - More details - Source on GitHub

📦 integration-tests/container-image/quarkus-standard-way

io.quarkus.it.container.image.GreetingResourceIT.testHelloEndpoint - More details - Source on GitHub

📦 integration-tests/devmode

io.quarkus.test.no.src.main.NoSrcMainUnitTest. - More details - Source on GitHub

📦 integration-tests/elytron-security-jdbc

io.quarkus.elytron.security.jdbc.it.ElytronSecurityJdbcTest.anonymous - More details - Source on GitHub

📦 integration-tests/elytron-security-ldap

io.quarkus.elytron.security.ldap.it.ElytronSecurityLdapTest.anonymous - More details - Source on GitHub

📦 integration-tests/google-cloud-functions-http

io.quarkus.it.gcp.functions.http.GreetingTest.testGreeting - More details - Source on GitHub

📦 integration-tests/grpc-health

io.quarkus.grpc.health.MicroProfileHealthDisabledTest. - More details - Source on GitHub

io.quarkus.grpc.health.MicroProfileHealthEnabledTest. - More details - Source on GitHub

📦 integration-tests/grpc-interceptors

io.quarkus.grpc.example.interceptors.HelloWorldEndpointTest.testHelloWorldServiceUsingBlockingStub - More details - Source on GitHub

📦 integration-tests/grpc-mutual-auth

io.quarkus.grpc.examples.hello.HelloWorldMutualTlsServiceTest.testHelloWorldServiceUsingBlockingStub - More details - Source on GitHub

📦 integration-tests/grpc-plain-text-gzip

io.quarkus.grpc.examples.hello.HelloWorldServiceTest.testHelloWorldServiceUsingBlockingStub - More details - Source on GitHub

📦 integration-tests/grpc-plain-text-mutiny

io.quarkus.grpc.examples.hello.HelloWorldServiceTest.testHelloWorldServiceUsingBlockingStub - More details - Source on GitHub

📦 integration-tests/grpc-proto-v2

io.quarkus.grpc.examples.hello.HelloWorldServiceTest.testHelloWorldServiceUsingBlockingStub - More details - Source on GitHub

📦 integration-tests/grpc-streaming

io.quarkus.grpc.example.streaming.StreamingEndpointTest.testPipe - More details - Source on GitHub

📦 integration-tests/grpc-tls

io.quarkus.grpc.examples.hello.HelloWorldTlsEndpointTest.testHelloWorldServiceUsingBlockingStub - More details - Source on GitHub

📦 integration-tests/injectmock

io.quarkus.it.mockbean.DummyResourceTest.testDummyAgain - More details - Source on GitHub

📦 integration-tests/jackson

io.quarkus.it.jackson.ModelWithSerializerAndDeserializerOnFieldResourceTest.testSerializer - More details - Source on GitHub

📦 integration-tests/jaxp

io.quarkus.it.jaxp.JaxpTest.transformer - More details - Source on GitHub

📦 integration-tests/jgit

io.quarkus.it.jgit.JGitTest.shouldClone - More details - Source on GitHub

📦 integration-tests/jpa-without-entity

org.test.HelloResourceTest.testHelloEndpoint - More details - Source on GitHub

📦 integration-tests/jsch

io.quarkus.it.jsch.JSchTest.shouldConnect - More details - Source on GitHub

📦 integration-tests/jsonb

io.quarkus.it.jsonb.ModelWithSerializerAndDeserializerOnFieldResourceTest.testSerializer - More details - Source on GitHub

📦 integration-tests/kubernetes-client

io.quarkus.it.kubernetes.client.ConfigMapPropertiesTest.testPropertiesReadFromConfigMap - More details - Source on GitHub

io.quarkus.it.kubernetes.client.KubernetesClientTest.testInteractionWithAPIServer - More details - Source on GitHub

io.quarkus.it.kubernetes.client.KubernetesNewClientTest.testInteractionWithAPIServer - More details - Source on GitHub

io.quarkus.it.kubernetes.client.KubernetesTestServerOnProfileTest.testConfiguration - More details - Source on GitHub

io.quarkus.it.kubernetes.client.KubernetesTestServerTest.testConfiguration - More details - Source on GitHub

io.quarkus.it.kubernetes.client.NamespacedConfigMapPropertiesTest.testPropertiesReadFromConfigMap - More details - Source on GitHub

io.quarkus.it.kubernetes.client.SecretPropertiesTest.testPropertiesReadFromConfigMap - More details - Source on GitHub

📦 integration-tests/kubernetes-service-binding-jdbc

io.quarkus.it.k8ssb.jdbc.FruitsEndpointTest.testListAllFruits - More details - Source on GitHub

📦 integration-tests/logging-gelf

io.quarkus.logging.gelf.it.GelfLogHandlerTest.test - More details - Source on GitHub

📦 integration-tests/logging-json

io.quarkus.it.logging.json.GreetingResourceTest.testHelloEndpoint - More details - Source on GitHub

📦 integration-tests/logging-min-level-set

io.quarkus.it.logging.minlevel.set.LoggingMinLevelPromoteTest.testError - More details - Source on GitHub

📦 integration-tests/logging-min-level-unset

io.quarkus.it.logging.minlevel.unset.LoggingMinLevelPromoteTest.testNotTrace - More details - Source on GitHub

📦 integration-tests/mailer

io.quarkus.it.mailer.MailerTest. - More details - Source on GitHub

📦 integration-tests/micrometer-mp-metrics

io.quarkus.it.micrometer.mpmetrics.MPMetricsTest.callPrimeGen_1 - More details - Source on GitHub

📦 integration-tests/micrometer-prometheus

io.quarkus.it.micrometer.prometheus.PrometheusMetricsRegistryTest.testRegistryInjection - More details - Source on GitHub

📦 integration-tests/mongodb-client

io.quarkus.it.mongodb.BookResourceTest. - More details - Source on GitHub

io.quarkus.it.mongodb.BookResourceWithParameterInjectionTest. - More details - Source on GitHub

📦 integration-tests/mongodb-panache-kotlin

io.quarkus.it.mongodb.panache.MongodbPanacheMockingTest.testPanacheRepositoryBridges - More details - Source on GitHub

📦 integration-tests/mongodb-panache

io.quarkus.it.mongodb.panache.MongodbPanacheMockingTest.testPanacheRepositoryBridges - More details - Source on GitHub

📦 integration-tests/mongodb-rest-data-panache

io.quarkus.it.mongodb.rest.data.panache.MongoDbRestDataPanacheTest.shouldNotCreateOrDeleteAuthor - More details - Source on GitHub

📦 integration-tests/narayana-jta

io.quarkus.narayana.jta.TransactionScopedTest.transactionScopedInTransaction - More details - Source on GitHub

📦 integration-tests/narayana-stm

org.acme.quickstart.stm.STMResourceTest.testGet - More details - Source on GitHub

📦 integration-tests/neo4j

io.quarkus.it.neo4j.Neo4jFunctionalityTest.testBlockingNeo4jFunctionality - More details - Source on GitHub

📦 integration-tests/openshift-client

io.quarkus.it.openshift.client.OpenShiftClientTest.createRoute - More details - Source on GitHub

📦 integration-tests/opentelemetry

io.quarkus.it.opentelemetry.OpenTelemetryTestCase.testDeepPathNaming - More details - Source on GitHub

📦 integration-tests/picocli-native

io.quarkus.it.picocli.PicocliTest.testCommands - More details - Source on GitHub

📦 integration-tests/quartz

io.quarkus.it.quartz.QuartzTestCase.testCount - More details - Source on GitHub

📦 integration-tests/qute

io.quarkus.it.qute.QuteTestCase.testTemplates - More details - Source on GitHub

📦 integration-tests/reactive-messaging-amqp

io.quarkus.it.amqp.AmqpConnectorTest.test - More details - Source on GitHub

📦 integration-tests/reactive-messaging-http

io.quarkus.reactivemessaging.http.ReactiveMessagingHttpTest.shouldSendAndConsumeWebSocketAndUseCustomSerializer - More details - Source on GitHub

📦 integration-tests/reactive-messaging-kafka

io.quarkus.it.kafka.KafkaConnectorTest.test - More details - Source on GitHub

📦 integration-tests/redis-client

io.quarkus.redis.it.QuarkusRedisWithParameterInjectionTest.reactive - More details - Source on GitHub

📦 integration-tests/rest-client

io.quarkus.it.rest.client.wronghost.ExternalWrongHostTestCase.restClient - More details - Source on GitHub

📦 integration-tests/resteasy-mutiny

io.quarkus.it.resteasy.mutiny.MutinyTest.testSerialization - More details - Source on GitHub

📦 integration-tests/resteasy-reactive-kotlin

io.quarkus.it.resteasy.reactive.kotlin.ReactiveGreetingResourceTest.testHello - More details - Source on GitHub

📦 integration-tests/resteasy-reactive-rest-client-standalone

io.quarkus.it.rest.client.BasicTest.shouldWork - More details - Source on GitHub

📦 integration-tests/resteasy-reactive-rest-client

io.quarkus.it.rest.client.BasicTest.shouldWork - More details - Source on GitHub

📦 integration-tests/simple with space

io.quarkus.it.spaces.GreetingResourceTest.testHelloEndpoint - More details - Source on GitHub

📦 integration-tests/smallrye-config

io.quarkus.it.smallrye.config.QuarkusTestProfileTest.testProfile - More details - Source on GitHub

io.quarkus.it.smallrye.config.SmallRyeConfigTest.dotenv - More details - Source on GitHub

📦 integration-tests/smallrye-context-propagation

io.quarkus.context.test.CustomProducersTest. - More details - Source on GitHub

io.quarkus.context.test.SimpleContextPropagationTest. - More details - Source on GitHub

io.quarkus.context.test.customContext.CustomContextTest. - More details - Source on GitHub

io.quarkus.context.test.mutiny.MutinyContextPropagationTest. - More details - Source on GitHub

📦 integration-tests/smallrye-graphql

io.quarkus.it.smallrye.graphql.GreetingsResourceTest.test - More details - Source on GitHub

📦 integration-tests/smallrye-metrics

io.quarkus.it.metrics.MetricsInheritanceTestCase.verifyRegistrations - More details - Source on GitHub

📦 integration-tests/tika

io.quarkus.it.tika.TikaParserTest.testGetTextFromPdfFormat - More details - Source on GitHub

📦 integration-tests/vertx-graphql

io.quarkus.vertx.graphql.it.VertxGraphqlTest. - More details - Source on GitHub

📦 integration-tests/virtual-http-resteasy

io.quarkus.it.virtual.FunctionTest.testNotFound - More details - Source on GitHub

📦 integration-tests/virtual-http

io.quarkus.it.virtual.FunctionTest.testNotFound - More details - Source on GitHub

📦 integration-tests/webjars-locator

io.quarkus.it.webjar.locator.WebJarResourceTest.testWebJar - More details - Source on GitHub

@essobedo essobedo force-pushed the 16599/filter-dependencies branch from 4795a69 to c28228a Compare April 18, 2021 18:26
* package with unused dependencies.
*/
@ConfigItem(defaultValue = "false")
public boolean filterOptionalDependencies;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you give a reasonable example of having configured optionalDependencies and wishing filterOptionalDependencies to be false?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aloubyansky No there is no such example. But I need a mechanism to enable the feature in order to distinguish, the case where we don't want to include any optional dependencies by not setting optionalDependencies intentionally and the case where optionalDependencies has not been set after migrating an application (what I called "backward compatibility reasons")

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like there is some config redundancy. I.e. if you specify which dependencies you want to keep, it implies the rest of the optional deps you will want to be filtered out.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure, I get what you mean. This is only a flag to enable the feature.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you don't use this flag, there are several tests with optional dependencies that fail because it will filter out all the optional dependencies

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's probably a sign of a bug? Why would all the optional dependencies be filtered out w/o it?
What I'm saying is if you configure optionalDependencies, you list the dependencies you want to keep. Which means the rest of the optional dependencies aren't desired, right?

Copy link
Contributor Author

@essobedo essobedo Apr 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's probably a sign of a bug? Why would all the optional dependencies be filtered out w/o it?

@aloubyansky No it is actually intended, let's say that you want to build your application twice with two different Quarkus profiles foo and bar. The code for bar needs one additional library "ext-bar". So the dependency "ext-bar" will be marked as optional, foo won't define anything for includedOptionalDependencies as it doesn't need any optional dependencies while bar will set ext-bar as includedOptionalDependencies. Do you see what I mean?

What I'm saying is if you configure optionalDependencies, you list the dependencies you want to keep. Which means the rest of the optional dependencies aren't desired, right?

That's right, it also means that if no optionalDependencies are configured and filterOptionalDependencies has been set to true, then it will not include any optional dependencies.

Here are the use cases:

  1. filterOptionalDependencies set to false (the default value), it will behaves like before in other words, the optional dependencies are not filtered whatever the value of includedOptionalDependencies since the feature is disabled (what I refer as "backward compatibility reasons")
  2. filterOptionalDependencies set to true and includedOptionalDependencies are absent, then all the optional dependencies are filtered out.
  3. filterOptionalDependencies set to true and includedOptionalDependencies are present, then only the optional dependencies in includedOptionalDependencies are kept, the rest is filtered out.

Is it clear enough now?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, thanks. This PR actually enables reasonable use-cases for optional dependencies in Quarkus apps. Otherwise, I am not sure they make sense in Quarkus apps. There is a use-case of re-augmenting mutable-jar packaged apps though. But even then it might benefit from these config options.

@essobedo essobedo force-pushed the 16599/filter-dependencies branch from c28228a to 8883c8d Compare April 19, 2021 07:57
@essobedo essobedo requested a review from aloubyansky April 19, 2021 07:58
@essobedo essobedo force-pushed the 16599/filter-dependencies branch from 8883c8d to bcc2e07 Compare April 19, 2021 10:14
@quarkus-bot
Copy link

quarkus-bot bot commented Apr 19, 2021

🚫 This workflow run has been cancelled.

Failing Jobs - Building 8883c8d

Status Name Step Test failures Logs Raw logs
JVM Tests - JDK 11 Build ⚠️ Check → Logs Raw logs
JVM Tests - JDK 11 Windows Build ⚠️ Check → Logs Raw logs
JVM Tests - JDK 15 Build ⚠️ Check → Logs Raw logs

@aloubyansky aloubyansky merged commit ab00a99 into quarkusio:main Apr 19, 2021
@quarkus-bot quarkus-bot bot added this to the 2.0 - main milestone Apr 19, 2021
@aloubyansky
Copy link
Member

Thanks @essobedo, great work! Would you mind writing an article about the multi-build config to the Quarkus guides [1] to promote the features you contributed?

@essobedo essobedo deleted the 16599/filter-dependencies branch April 20, 2021 05:23
@essobedo
Copy link
Contributor Author

Thanks @essobedo, great work! Would you mind writing an article about the multi-build config to the Quarkus guides [1] to promote the features you contributed?

@aloubyansky Yes, of course, with pleasure, but If you don't mind, I would like first to address the issue with the parallel build to propose a complete solution. Is that ok with you or you rather prefer that I write the article first?

@aloubyansky
Copy link
Member

Thanks! Whatever you prefer. The profile/parallel build might not be a quick fix.

@essobedo
Copy link
Contributor Author

I know that it's not a quick fix but I have something in mind that I would like to test (this Friday), if it does work then I will work on the article first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow to filter dependencies in multi-build mode
2 participants