Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -508,10 +508,82 @@
"Constructor has been removed"
]
},
{
"type": "org.gradle.api.plugins.BasePluginExtension",
"member": "Class org.gradle.api.plugins.BasePluginExtension",
"acceptation": "The functionality was already available for several releases in BasePluginConvention",
"changes": []
},
{
"type": "org.gradle.api.plugins.BasePluginExtension",
"member": "Method org.gradle.api.plugins.BasePluginExtension.getArchivesBaseName()",
"acceptation": "The functionality was already available for several releases in BasePluginConvention",
"changes": [
"ANNOTATION_DEPRECATED_ADDED"
]
},
{
"type": "org.gradle.api.plugins.BasePluginExtension",
"member": "Method org.gradle.api.plugins.BasePluginExtension.getArchivesName()",
"acceptation": "The functionality was already available for several releases in BasePluginConvention",
"changes": []
},
{
"type": "org.gradle.api.plugins.BasePluginExtension",
"member": "Method org.gradle.api.plugins.BasePluginExtension.getDistsDirectory()",
"acceptation": "The functionality was already available for several releases in BasePluginConvention",
"changes": []
},
{
"type": "org.gradle.api.plugins.BasePluginExtension",
"member": "Method org.gradle.api.plugins.BasePluginExtension.getDistsDirName()",
"acceptation": "The functionality was already available for several releases in BasePluginConvention",
"changes": [
"ANNOTATION_DEPRECATED_ADDED"
]
},
{
"type": "org.gradle.api.plugins.BasePluginExtension",
"member": "Method org.gradle.api.plugins.BasePluginExtension.getLibsDirectory()",
"acceptation": "The functionality was already available for several releases in BasePluginConvention",
"changes": []
},
{
"type": "org.gradle.api.plugins.BasePluginExtension",
"member": "Method org.gradle.api.plugins.BasePluginExtension.getLibsDirName()",
"acceptation": "The functionality was already available for several releases in BasePluginConvention",
"changes": [
"ANNOTATION_DEPRECATED_ADDED"
]
},
{
"type": "org.gradle.api.plugins.BasePluginExtension",
"member": "Method org.gradle.api.plugins.BasePluginExtension.setArchivesBaseName(java.lang.String)",
"acceptation": "The functionality was already available for several releases in BasePluginConvention",
"changes": [
"ANNOTATION_DEPRECATED_ADDED"
]
},
{
"type": "org.gradle.api.plugins.BasePluginExtension",
"member": "Method org.gradle.api.plugins.BasePluginExtension.setDistsDirName(java.lang.String)",
"acceptation": "The functionality was already available for several releases in BasePluginConvention",
"changes": [
"ANNOTATION_DEPRECATED_ADDED"
]
},
{
"type": "org.gradle.api.plugins.BasePluginExtension",
"member": "Method org.gradle.api.plugins.BasePluginExtension.setLibsDirName(java.lang.String)",
"acceptation": "The functionality was already available for several releases in BasePluginConvention",
"changes": [
"ANNOTATION_DEPRECATED_ADDED"
]
},
{
"type": "org.gradle.testing.jacoco.tasks.JacocoCoverageVerification",
"member": "Method org.gradle.testing.jacoco.tasks.JacocoCoverageVerification.getDummyOutputFile()",
"acceptation": "This method is for internal use only",
"acceptation": "Documented as internal",
"changes": []
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,7 @@ public void setConfigurationContainer(ConfigurationContainer configurationContai

@Override
public Convention getConvention() {
// TODO (donat) deprecate after all internal usages have been eliminated
return extensibleDynamicObject.getConvention();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1741,7 +1741,9 @@ org:leaf2:1.0
group = 'org.foo'
version = '1.0'
}
archivesBaseName = 'root'
base {
archivesBaseName = 'root'
}
dependencies {
implementation project(":impl")
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<section>
<section>
<title>Properties</title>
<table>
<thead>
<tr>
<td>Name</td>
<td>Default with <literal>java</literal> plugin</td>
</tr>
</thead>
<tr>
<td>distsDirectory</td>
<td><literal><replaceable>${project.buildDir}</replaceable>/distributions</literal></td>
</tr>
<tr>
<td>libsDirectory</td>
<td><literal><replaceable>${project.buildDir}</replaceable>/libs</literal></td>
</tr>
<tr>
<td>archivesName</td>
<td><literal>project.name</literal></td>
</tr>
</table>
</section>
<section>
<title>Methods</title>
<table>
<thead>
<tr>
<td>Name</td>
</tr>
</thead>
</table>
</section>
</section>
1 change: 1 addition & 0 deletions subprojects/docs/src/docs/dsl/plugins.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<plugins>
<plugin id="java" description="Java Plugin">
<extends targetClass="org.gradle.api.Project" mixinClass="org.gradle.api.plugins.BasePluginConvention"/>
<extends targetClass="org.gradle.api.Project" mixinClass="org.gradle.api.plugins.BasePluginExtension"/>
<extends targetClass="org.gradle.api.Project" mixinClass="org.gradle.api.plugins.JavaPluginConvention"/>
<extends targetClass="org.gradle.api.Project" mixinClass="org.gradle.api.plugins.JavaPluginExtension"/>
<extends targetClass="org.gradle.api.Project" id="reporting" extensionClass="org.gradle.api.reporting.ReportingExtension"/>
Expand Down
28 changes: 21 additions & 7 deletions subprojects/docs/src/docs/userguide/core-plugins/base_plugin.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -66,27 +66,41 @@ A standard configuration for the production artifacts of a project.

Note that the `assemble` task generates all artifacts that are attached to the `archives` configuration.

[[sec:base_plugin_conventions]]
== Conventions
[[sec:base_plugin_extension]]
== Contributed extensions

The Base Plugin adds the link:{groovyDslPath}/org.gradle.api.plugins.BasePluginExtension.html[`base` extension] to the project.
This allows to configure the following properties inside a dedicated DSL block.

The Base Plugin only adds conventions related to the creation of archives, such as ZIPs, TARs and JARs. Specifically, it provides the following project properties that you can set:
.Using the `base` extension
====
include::sample[dir="snippets/files/archivesChangedBaseName/groovy",files="build.gradle[tags=base-plugin-config]"]
include::sample[dir="snippets/files/archivesChangedBaseName/kotlin",files="build.gradle.kts[tags=base-plugin-config]"]
====

`archivesBaseName` — default: `$project.name`::
`archivesName` — default: `$project.name`::
Provides the default link:{groovyDslPath}/org.gradle.api.tasks.bundling.AbstractArchiveTask.html#org.gradle.api.tasks.bundling.AbstractArchiveTask:archiveBaseName[AbstractArchiveTask.getArchiveBaseName()] for archive tasks.

`distsDirName` — default: _distributions_::
`distsDirectory` — default: `$buildDir/distributions`::
Default name of the directory in which distribution archives, i.e. non-JARs, are created.

`libsDirName` — default: _libs_::
`libsDirectory` — default: `$buildDir/libs`::
Default name of the directory in which library archives, i.e. JARs, are created.

The plugin also provides default values for the following properties on any task that extends link:{groovyDslPath}/org.gradle.api.tasks.bundling.AbstractArchiveTask.html[AbstractArchiveTask]:

`destinationDirectory`::
Defaults to __``$buildDir``/``$distsDirName``__ for non-JAR archives and __``$buildDir``/``$libsDirName``__ for JARs and derivatives of JAR, such as WARs.
Defaults to `distsDirectory` for non-JAR archives and `libsDirectory` for JARs and derivatives of JAR, such as WARs.

`archiveVersion`::
Defaults to `$project.version` or 'unspecified' if the project has no version.

`archiveBaseName`::
Defaults to `$archivesBaseName`.

[[sec:base_plugin_conventions]]
== Conventions (deprecated)

The Base Plugin also adds conventions related to the creation of archives, such as ZIPs, TARs and JARs.
These are *deprecated* and superseded by the extension described above.
See the link:{groovyDslPath}/org.gradle.api.plugins.BasePluginConvention.html[BasePluginConvention] DSL documentation for information on them.
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,23 @@ Now, the situation has been cleared and all build should use the `maven-publish`
The last remaining artifact of the old way of publishing is the `Upload` task that has been deprecated and scheduled for removal in Gradle 8.0.
Existing clients should migrate to the <<publishing_maven.adoc#publishing_maven,`maven-publish` plugin>>.

[[base_convention_deprecation]]
=== Deprecated `base` plugin conventions

The convention properties contributed by the `base` plugin have been deprecated and scheduled for removal in Gradle 8.0.
The conventions are replaced by the the `base { }` configuration block backed by link:{groovyDslPath}/org.gradle.api.plugins.BasePluginExtension.html[BasePluginExtension].

The old convention object defines the `distsDirName`, `libsDirName` and `archivesBaseName` properties with simple getter and setter methods.
Those methods are available in the extension only to maintain backwards compatibility.
Build scripts should solely use the properties of type `Property`:
```
base {
archivesName = 'customBase'
distsDirectory = layout.buildDirectory.dir('custom-dist')
libsDirectory = layout.buildDirectory.dir('custom-libs')
}
```
Comment on lines +209 to +215

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to link to a snippet from the upgrade guide, like it is done from base_plugin.adoc?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we want that.

In this case, we want to capture how to upgrade from Gradle 7.0 to 7.1. If we link the snippet to the upgrade guide and later - say, in 7.2 - change the snippet, the freshly rendered upgrade guide might have instructions that's invalid for the 7.0 -> 7.1 upgrade.


[[application_convention_deprecation]]
=== Deprecated `ApplicationPluginConvention`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@ plugins {
}

version = 1.0
archivesBaseName = "gradle"
// tag::base-plugin-config[]
base {
archivesName = "gradle"
distsDirectory = layout.buildDirectory.dir('custom-dist')
libsDirectory = layout.buildDirectory.dir('custom-libs')
}
// end::base-plugin-config[]

tasks.register('myZip', Zip) {
from 'somedir'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@ plugins {
}

version = "1.0"
base.archivesBaseName = "gradle"

// tag::base-plugin-config[]
base {
archivesName.set("gradle")
distsDirectory.set(layout.buildDirectory.dir("custom-dist"))
libsDirectory.set(layout.buildDirectory.dir("custom-libs"))
}
// end::base-plugin-config[]

val myZip by tasks.registering(Zip::class) {
from("somedir")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ public void canCustomizeArchiveNamesUsingConventionProperties() {
buildFile.writelns(
"apply plugin: 'war'",
"buildDir = 'output'",
"libsDirName = 'archives'",
"archivesBaseName = 'test'",
"base {",
" archivesName = 'test'",
" libsDirectory = layout.buildDirectory.dir('archives')",
"}",
"version = '0.5-RC2'"
);
testFile("src/main/resources/org/gradle/resource.file").write("some resource");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,9 @@ project(":project3") {
def "ivy-publish plugin does not take archivesBaseName into account"() {
createBuildScripts("""
project(":project2") {
archivesBaseName = "changed"
base {
archivesName = "changed"
}
}
""")

Expand Down Expand Up @@ -226,7 +228,9 @@ project(":project1") {
}
project(":project2") {
apply plugin: 'java'
archivesBaseName = "changed"
base {
archivesName = "changed"
}
}
"""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,9 @@ class PrecompiledScriptPluginIntegrationTest : AbstractPluginIntegrationTest() {
"""
plugins { base }

base.archivesBaseName = "my"
base {
archivesName.set("my")
}

println("base")
"""
Expand Down Expand Up @@ -228,7 +230,9 @@ class PrecompiledScriptPluginIntegrationTest : AbstractPluginIntegrationTest() {
"""
plugins { base }

base.archivesBaseName = "my"
base {
archivesName.set("my")
}
"""
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,9 @@ project(":project3") {
def "maven-publish plugin does not take archivesBaseName into account when publishing"() {
createBuildScripts("""
project(":project2") {
archivesBaseName = "changed"
base {
archivesName = "changed"
}
}
""")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@
import org.gradle.api.internal.plugins.DefaultArtifactPublicationSet;
import org.gradle.api.internal.project.ProjectInternal;
import org.gradle.api.plugins.internal.DefaultBasePluginConvention;
import org.gradle.api.plugins.internal.DefaultBasePluginExtension;
import org.gradle.api.tasks.bundling.AbstractArchiveTask;
import org.gradle.internal.deprecation.DeprecatableConfiguration;
import org.gradle.jvm.tasks.Jar;
import org.gradle.language.base.plugins.LifecycleBasePlugin;

/**
* <p>A {@link org.gradle.api.Plugin} which defines a basic project lifecycle and some common convention properties.</p>
* <p>A {@link org.gradle.api.Plugin} which defines a basic project lifecycle and some common convention properties.</p>
*
* @see <a href="https://docs.gradle.org/current/userguide/base_plugin.html">Base plugin reference</a>
*/
Expand All @@ -43,30 +44,37 @@ public class BasePlugin implements Plugin<Project> {
public void apply(final Project project) {
project.getPluginManager().apply(LifecycleBasePlugin.class);

BasePluginConvention convention = new DefaultBasePluginConvention(project);
BasePluginExtension baseExtension = project.getExtensions().create(BasePluginExtension.class, "base", DefaultBasePluginExtension.class, project);
BasePluginConvention convention = new DefaultBasePluginConvention(baseExtension);

project.getConvention().getPlugins().put("base", convention);

configureExtension(project, baseExtension);
configureBuildConfigurationRule(project);
configureArchiveDefaults(project, convention);
configureArchiveDefaults(project, baseExtension);
configureConfigurations(project);
configureAssemble((ProjectInternal) project);
}

private void configureArchiveDefaults(final Project project, final BasePluginConvention pluginConvention) {
private void configureExtension(Project project, BasePluginExtension extension) {
extension.getArchivesName().convention(project.getName());
extension.getLibsDirectory().convention(project.getLayout().getBuildDirectory().dir("libs"));
extension.getDistsDirectory().convention(project.getLayout().getBuildDirectory().dir("distributions"));
}

private void configureArchiveDefaults(final Project project, final BasePluginExtension extension) {
project.getTasks().withType(AbstractArchiveTask.class).configureEach(task -> {
if (task instanceof Jar) {
task.getDestinationDirectory().convention(pluginConvention.getLibsDirectory());
task.getDestinationDirectory().convention(extension.getLibsDirectory());
} else {
task.getDestinationDirectory().convention(pluginConvention.getDistsDirectory());
task.getDestinationDirectory().convention(extension.getDistsDirectory());
}

task.getArchiveVersion().convention(
project.provider(() -> project.getVersion() == Project.DEFAULT_VERSION ? null : project.getVersion().toString())
);

task.getArchiveBaseName().convention(
project.provider(() -> pluginConvention.getArchivesBaseName())
);
task.getArchiveBaseName().convention(extension.getArchivesName());
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@

/**
* <p>A {@link Convention} used for the BasePlugin.</p>
*
* @deprecated Use {@link BasePluginExtension} instead. This class is scheduled for removal in Gradle 8.0.
*/
@Deprecated
public abstract class BasePluginConvention {
/**
* Returns the directory to generate TAR and ZIP archives into.
Expand Down
Loading