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

Optional dependencies are not picked up #47

Closed
DieBauer opened this issue Jan 10, 2020 · 4 comments · Fixed by #48
Closed

Optional dependencies are not picked up #47

DieBauer opened this issue Jan 10, 2020 · 4 comments · Fixed by #48

Comments

@DieBauer
Copy link
Contributor

I'm using this plugin to sanitize my dependencies, thanks for that!

But I'm now running into an issue that one module is using optional dependencies.

val h2database = "com.h2database" % "h2" % "1.2.147" % "optional"

But this dependency now keeps on showing up in undeclared dependencies.
I see

moduleID.configurations.fold[Boolean](true)(conf => conf.split("; ?").exists(c => c.startsWith("compile") || c.startsWith("provided")))
that compile and provided scope is supported.

Can we also support optional?

@cb372
Copy link
Owner

cb372 commented Jan 10, 2020

Yes, that seems reasonable.

I feel like I deliberately chose not to include optional dependencies, but I can't remember why... I can't think of a good reason not to include them.

Do you want to make a PR? If so, please include a scripted test for it. https://github.com/cb372/sbt-explicit-dependencies/tree/master/src/sbt-test/basic/no-unused-no-undeclared-provided is probably a good test to use as a reference.

@DieBauer
Copy link
Contributor Author

Let me see what I can come up with!

@cb372
Copy link
Owner

cb372 commented Jan 15, 2020

@DieBauer Thanks for the PR. I'll take a look at it now.

Out of curiosity, why does your project have h2 as an optional dependency instead of a normal compile-time dependency? Is your project a library or an application? I'd like to understand more about your use case, because I haven't encountered many optional dependencies in the wild.

Do you have some kind of conditional code, along the lines of

if (h2isOnTheClasspath) {
  useH2()
}

?

@DieBauer
Copy link
Contributor Author

DieBauer commented Jan 16, 2020

That's exactly the use case. For me it is a spring-boot module/library, that has some classes with @ConditionalOnClass(...). Thus effectively toggling features depending on classpath configuration.

So instead of multiple artifacts for every 'flavour', it is one artifact with optional behaviour ;)

@cb372 cb372 closed this as completed in #48 Jan 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants