Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[MASSEMBLY-832] Consider dependency optional attribute when gather de...#49

Open
zabetak wants to merge 2 commits into
apache:master from
zabetak:MASSEMBLY-832
Open

[MASSEMBLY-832] Consider dependency optional attribute when gather de... #49
zabetak wants to merge 2 commits into
apache:master from
zabetak:MASSEMBLY-832

Conversation

@zabetak

@zabetak zabetak commented Dec 1, 2021
edited by hboutemy
Loading

Copy link
Copy Markdown
Member

https://issues.apache.org/jira/browse/MASSEMBLY-832

Maven allows to declare dependencies as optional and this is important for various reasons (e.g., avoiding licensing problems).

This change provides a convenient way to include/exclude optional dependencies in a dependencySet.

By default optional dependencies are excluded from the dependencySet. An optional dependency shouldn't be packaged, distributed, or transitively inherited unless specified explicitly so it makes sense to exclude them by default.

Following this checklist to help us incorporate your contribution quickly and easily:

  • Make sure there is a JIRA issue filed
    for the change (usually before you start working on it). Trivial changes like typos do not
    require a JIRA issue. Your pull request should address just this issue, without
    pulling in other changes.
  • Each commit in the pull request should have a meaningful subject line and body.
  • Format the pull request title like [MASSEMBLY-XXX] - Fixes bug in ApproximateQuantiles,
    where you replace MASSEMBLY-XXX with the appropriate JIRA issue. Best practice
    is to use the JIRA issue title in the pull request title and in the first line of the
    commit message.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Run mvn clean verify to make sure basic checks pass. A more thorough check will
    be performed on your pull request automatically.
  • You have run the integration tests successfully (mvn -Prun-its clean verify).

If your pull request is about ~20 lines of code you don't need to sign an
Individual Contributor License Agreement if you are unsure
please ask on the developers list.

To make clear that you license your contribution under the Apache License Version 2.0, January 2004 you have to acknowledge this by using the following check-box.

Comment thread src/main/mdo/assembly-component.mdo Outdated
<name>useOptionalDependencies</name>
<version>2.1.0+</version>
<type>boolean</type>
<defaultValue>false</defaultValue>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I wonder if the defallt here should be true to avoid changing existing behavior.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I changed the default to true to retain the previous behavior.

<field>
<name>useOptionalDependencies</name>
<version>2.1.0+</version>
<type>boolean</type>

@elharo elharo Dec 12, 2024
edited
Loading

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this a boolean or a list? What if someone wants to include some optional dependencies and not others?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

They could possibly achieve this by declaring a separate dependencySet. It doesn't make much sense to make this very specific cause in that case we could use the existing include/exclude options.

private Set<Artifact> resolveDependencyArtifacts( DependencySet dependencySet, Set<Artifact> artifacts ) throws Exception
{
MavenProject project = new MavenProject(new Model());
Logger logger = new ConsoleLogger(Logger.LEVEL_DEBUG, "test");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

no logging at all please. Use a SilentLogger

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Removed the logger as part of the rebase.

Copy link
Copy Markdown

Resolve #1056

zabetak commented Jun 25, 2025

Copy link
Copy Markdown
Member Author

Thanks for the review @elharo ! I rebased the PR against master, addressed all review comments, and also added a new integration test for the new functionality.


@Test
public void testGetDependencyArtifacts_ShouldFilterOptionalArtifactsExplicitly() throws Exception {
Artifact am1 = mockArtifact(1);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

am1 --> artifact1
am2 --> artifact2

here and elsewhere avoid abbreviations

}

private static Artifact mockArtifact(int id) {
Artifact a = mock(Artifact.class);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

a --> artifact


@Test
public void testGetDependencyArtifacts_ShouldNotFilterOptionalArtifactsByDefault() throws Exception {
Artifact am1 = mockArtifact(1);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

no need to sue mocks here. You can simply create a DefaultArtifact.

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

Reviewers

@elharo elharo elharo requested changes

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /