Skip to content

Enable including test scope inputs when publishing #3483

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

Closed
majk-p opened this issue Feb 7, 2025 · 4 comments · Fixed by #3538
Closed

Enable including test scope inputs when publishing #3483

majk-p opened this issue Feb 7, 2025 · 4 comments · Fixed by #3538
Assignees
Labels
experimental Tickets tied to experimental features. missing feature Something should have been implemented, but wasn't. publish command
Milestone

Comments

@majk-p
Copy link
Contributor

majk-p commented Feb 7, 2025

Version(s) 1.6.1

Describe the bug
When packaging sources with scala-cli publish, sources within test directories are omitted even when they contain regular sources that are not tests. This can lead to missing classes in published jars.

Additionally, this behavior is not documented under https://scala-cli.virtuslab.org/docs/commands/publishing/publish

To Reproduce
Clone https://github.com/majk-p/scala-cli-publish-test and run ./package-and-check.sh

Expected behaviour
I appreciate that publishing is an experimental feature and I see how this might just be a very simple implementation for skipping test sources. I ideal world Scala CLI would simply knew if the file contains references to test framework but implementing that sounds impractical for a niche issue like this one.

A practical solution that would be backwards compatible could be a setting like "always-include-path" that would include a path (one or more) that won't be filtered out.

Anything that can help me include ./test/testapi.scala from the reproduction repo in published jar will be enough.

@majk-p majk-p added the bug Something isn't working label Feb 7, 2025
@Gedochao
Copy link
Contributor

When packaging sources with scala-cli publish, sources within test directories are omitted even when they contain regular sources that are not tests.

@majk-p ok, so first things first, this is not a bug and it's meant to work this way. The test and main scopes should not be compiled together by default here, as per the docs: https://scala-cli.virtuslab.org/docs/commands/test#test-sources

However, I agree we should enable publishing test sources, both to be included in a common fat JAR (behind a flag, like compile's --test) and a separate, test JAR (that'd be out of scope for this ticket, I think - although valid as a separate feature request).

While this issue is not a duplicate per se, the solution to this is the same as:

We have a --test command line option available for the compile sub-command, but we don't support it for other build commands. We should make it available for all sub-commands building the project, including publish. Just note that this requires a wide-scale refactor of all build commands, which is why it hasn't been done yet.

Will be treated as a feature request, thanks for raising.

@Gedochao Gedochao added missing feature Something should have been implemented, but wasn't. publish command experimental Tickets tied to experimental features. and removed bug Something isn't working labels Feb 10, 2025
@Gedochao Gedochao changed the title Publish command skips regular sources within test paths Enable including test scope inputs when publishing Feb 10, 2025
@ghostbuster91
Copy link
Contributor

@Gedochao Thanks for the reply. I agree that the test and main scopes should not be compiled together. I also agree about making it possible to publish test sources when needed.

What I think is a bit misleading here is how the test scope is defined.
I wouldn't expect files under ./src/main/com/company/example/test/.. to end up in the test scope.

@Gedochao
Copy link
Contributor

What I think is a bit misleading here is how the test scope is defined. I wouldn't expect files under ./src/main/com/company/example/test/.. to end up in the test scope.

@ghostbuster91 Anything with a directory named test on its path is considered a part of the test scope.
AFAIK, it's always been so, and it's documented as such.
https://scala-cli.virtuslab.org/docs/commands/test/#test-sources

@ghostbuster91
Copy link
Contributor

ghostbuster91 commented Feb 10, 2025

AFAIK, it's always been so, and it's documented as such.

I get that. I am only saying that this is quite uncommon in the scala land and I cannot recall any other tool that does that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
experimental Tickets tied to experimental features. missing feature Something should have been implemented, but wasn't. publish command
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

3 participants