<commit_before>NOTE: You can open this sample inside an IDE using the https://www.jetbrains.com/help/idea/gradle.html#gradle_import_project_start[IntelliJ native importer] or https://projects.eclipse.org/projects/tools.buildship[Eclipse Buildship].

This sample shows how precompiled script plugins can be used to compose build logic.

== Use case

Use case for this sample is an organization that produces two types of artifacts - services and libraries.
We want to apply a set of code quality checking rules to both artifact types and configure some aspects specific to each type.

This is achieved by implementing three separate plugins:

* `com.example.java-convention` - configures conventions that are generic for Java codebase in an organization.
* `com.example.library` - configures publishing to company's repository.
* `com.example.service` - configures `integrationTest` task and source set and mandatory service README section check.

The `com.example.library` and `com.example.service` plugins both apply the `com.example.java-convention` plugin.
In addition, they configure specifics for library and service artifacts.

All plugins created in this sample contain functional tests that use link:{userManualPath}/test_kit.html[TestKit] to verify their behaviour.

The intended use for this project is to build and publish the plugins to a repository and consume them in other projects.

=== Applying an external plugin in precompiled script plugin

The `com.example.java-convention` plugin uses SpotBugs plugin to perform static code analysis.
SpotBugs is an external plugin - external plugins currently link:{userManualPath}/custom_plugins.html#applying_external_plugins_in_precompiled_script_plugins[cannot be used in a precompiled script plugins
the same way they are used in build scripts - they have to be added as implementation dependencies to the plugin's project]:
====
include::sample[dir="groovy",files="build.gradle[tags=repositories-and-dependencies]"]
include::sample[dir="kotlin",files="build.gradle.kts[tags=repositories-and-dependencies]"]
====
Note here:

* the dependency artifact coordinates are different from the plugin id, which is `com.github.spotbugs`
* `gradlePluginPortal()` repository is added in `repositories` section
* plugin version is determined from the dependency version

Now the external plugin can be applied in precompiled script plugin by id:
====
include::sample[dir="groovy",files="src/main/groovy/com.example.java-convention.gradle[tags=apply-external-plugin]"]
include::sample[dir="kotlin",files="src/main/kotlin/com.example.java-convention.gradle.kts[tags=apply-external-plugin]"]
====<commit_msg>Document how to consume published precompiled plugins in a sample<commit_after>NOTE: You can open this sample inside an IDE using the https://www.jetbrains.com/help/idea/gradle.html#gradle_import_project_start[IntelliJ native importer] or https://projects.eclipse.org/projects/tools.buildship[Eclipse Buildship].

This sample shows how precompiled script plugins can be used to compose build logic in a real world scenario.

== Use case

Let's take as an example an organization that produces two types of artifacts - services and libraries.
We want to apply a set of code quality checking rules to both artifact types and configure some aspects specific to each type.

This is achieved by implementing three separate plugins:

* `com.example.java-convention` - configures conventions that are generic for Java codebase in an organization.
* `com.example.library` - configures publishing to company's repository.
* `com.example.service` - configures `integrationTest` task and source set and mandatory service README section check.

The `com.example.library` and `com.example.service` plugins both apply the `com.example.java-convention` plugin.
In addition, they configure specifics for library and service artifacts.

All plugins created in this sample contain functional tests that use link:{userManualPath}/test_kit.html[TestKit] to verify their behaviour.

The intended use for this sample project is to build and publish the plugins to a repository and consume them in other standalone projects:
====
include::sample[dir="groovy",files="build.gradle[tags=publishing]"]
include::sample[dir="kotlin",files="build.gradle.kts[tags=publishing]"]
====

The plugins can be published to a pre-configured repository by running:

[listing.terminal]
----
$ ./gradlew publish
----

The sample contains an example consumer project in `consumer-service` that demonstrates how the plugins can be consumed in a standalone project:
====
include::sample[dir="groovy/consumer-service",files="settings.gradle[];build.gradle[]"]
include::sample[dir="kotlin/consumer-service",files="settings.gradle.kts[];build.gradle.kts[]"]
====

=== Applying an external plugin in precompiled script plugin

The `com.example.java-convention` plugin uses SpotBugs plugin to perform static code analysis.
SpotBugs is an external plugin - external plugins currently link:{userManualPath}/custom_plugins.html#applying_external_plugins_in_precompiled_script_plugins[cannot be used in a precompiled script plugins
the same way they are used in build scripts - they have to be added as implementation dependencies to the plugin's project]:
====
include::sample[dir="groovy",files="build.gradle[tags=repositories-and-dependencies]"]
include::sample[dir="kotlin",files="build.gradle.kts[tags=repositories-and-dependencies]"]
====
Note here:

* the dependency artifact coordinates are different from the plugin id, which is `com.github.spotbugs`
* `gradlePluginPortal()` repository is added in `repositories` section
* plugin version is determined from the dependency version

Now the external plugin can be applied in precompiled script plugin by id:
====
include::sample[dir="groovy",files="src/main/groovy/com.example.java-convention.gradle[tags=apply-external-plugin]"]
include::sample[dir="kotlin",files="src/main/kotlin/com.example.java-convention.gradle.kts[tags=apply-external-plugin]"]
====
{'fraction_non_alphanumeric': 0.09113587227673374, 'fraction_numerical': 0.0, 'mean_word_length': 6.0093240093240095, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '835060', 'n_tokens_mistral': 1616, 'n_tokens_neox': 1514, 'n_words': 600}