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

Add an option to not publish test fixtures #779

Open
osipxd opened this issue May 13, 2024 · 4 comments
Open

Add an option to not publish test fixtures #779

osipxd opened this issue May 13, 2024 · 4 comments
Labels

Comments

@osipxd
Copy link

osipxd commented May 13, 2024

Context

I need to use test fixtures only internally between modules, so I don't want to publish them into Maven Central. I have the following code to exclude test fixtures from publication:

plugins.withId("org.gradle.java-test-fixtures") {
    val component = JavaPluginHelper.getJavaComponent(project) as DefaultJvmSoftwareComponent
    val feature = component.features.getByName(TestFixturesSupport.TEST_FIXTURES_FEATURE_NAME)
    component.withVariantsFromConfiguration(feature.apiElementsConfiguration) { skip() }
    component.withVariantsFromConfiguration(feature.runtimeElementsConfiguration) { skip() }
}

However, gradle-maven-publish-plugin forces publication of testFixturesSourcesElements whether or not other test fixture components are published.

Proposal

I see two options:

  1. Do not configure testFixturesSourcesElements publication if other test fixtures components are skipped from publication
  2. Add option to platform configuration allowing to disable test fixtures publication.
@osipxd
Copy link
Author

osipxd commented May 13, 2024

However, I've found a workaround:

// Exclude test fixtures from publication, as we use it only internally
plugins.withId("org.gradle.java-test-fixtures") {
    val component = components["java"] as AdhocComponentWithVariants
    component.withVariantsFromConfiguration(configurations["testFixturesApiElements"]) { skip() }
    component.withVariantsFromConfiguration(configurations["testFixturesRuntimeElements"]) { skip() }

    // Workaround to not publish test fixtures sources added by com.vanniktech.maven.publish plugin
    // TODO: Remove as soon as https://github.com/vanniktech/gradle-maven-publish-plugin/issues/779 closed
    afterEvaluate {
        component.withVariantsFromConfiguration(configurations["testFixturesSourcesElements"]) { skip() }
    }
}

osipxd added a commit to osipxd/encrypted-datastore that referenced this issue May 13, 2024
osipxd added a commit to osipxd/encrypted-datastore that referenced this issue May 13, 2024
@gabrielittner
Copy link
Collaborator

Having one of the 2 options built into the plugin is reasonable, I'll look into that.

Could you also open a feature request for Gradle directly? This would be benefitial for either option, for option 1 it would mean that we could read whatever config they have to disable the publication and for option 2 it would mean we can use their API internally. It would also remove the need to access internal types like DefaultJvmSoftwareComponent.

@osipxd
Copy link
Author

osipxd commented May 28, 2024

Created the issue for Gradle:

@osipxd osipxd changed the title Add option to not publish test fixtures Add an option to not publish test fixtures May 28, 2024
@osipxd
Copy link
Author

osipxd commented May 30, 2024

Oh, it looks like it is actually possible to disable test fixtures publication without internal APIs, so I've updated the workaround to get rid of internal APIs usage.

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

No branches or pull requests

2 participants