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

Expose addSourcePaths function for directory dependencies #30

Merged
merged 11 commits into from
Feb 25, 2022

Conversation

DSteve595
Copy link
Contributor

@DSteve595 DSteve595 commented Feb 16, 2022

This adds fun addSourcePaths(sourcePaths: Any) to the plugin's extension. It can be used when including source directories for generated code, which often come as FileCollections with task dependencies. Using a ConfigurableFileCollection as a task input lets us automatically run those dependency tasks when applicable.

A practical example is including a KotlinSourceSet's source directories in the signature file:

metalava {
  val consumerSourceSetNames = setOf("androidMain", "desktopMain")
  val kotlinSourceFileCollection = files(paths = emptyArray<Any>()) {
    consumerSourceSetNames
      .flatMap {
        val sourceSet = kotlin.sourceSets.getByName(it)
        sourceSet.dependsOn + sourceSet
      }
      .forEach { from(it.kotlin.sourceDirectories) }
  }

  addSourcePaths(kotlinSourceFileCollection)
}

This will ensure even generated code properly gets seen by Metalava.

@DSteve595 DSteve595 changed the title Expose addSourcePath function for directory dependencies Expose addSourcePaths function for directory dependencies Feb 16, 2022
@DSteve595
Copy link
Contributor Author

DSteve595 commented Feb 16, 2022

Superseded by #31, which handles this in a less manual way. Technically less flexible, but I can't think of any use cases for adding a source path that isn't on the compile classpath.

@DSteve595 DSteve595 closed this Feb 16, 2022
@DSteve595 DSteve595 deleted the sourcepath-filecollection branch February 16, 2022 19:47
@DSteve595 DSteve595 restored the sourcepath-filecollection branch February 17, 2022 00:06
@DSteve595
Copy link
Contributor Author

Actually, reopening since this would currently be the only way to add a directory that isn't named "java"/"kotlin". That restriction is a bit unexpected.

@DSteve595 DSteve595 reopened this Feb 17, 2022
@tylerbwong
Copy link
Owner

Looks good, just needs a formatting fix and ./gradlew metalavaGenerateSignature to reflect the new API.

tylerbwong
tylerbwong previously approved these changes Feb 19, 2022
@tylerbwong tylerbwong merged commit c3ab42a into tylerbwong:main Feb 25, 2022
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 this pull request may close these issues.

2 participants