Skip to content

Commit

Permalink
Merge pull request #20691 Fix composite build sample documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
bot-gradle committed Jun 3, 2022
2 parents ff6826a + 762965b commit 270f942
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ abstract class MavenConversionIntegrationTest extends AbstractInitIntegrationSpe
!warSubprojectBuildFile.text.contains("options.encoding")

assertContainsPublishingConfig(conventionPluginScript, scriptDsl)
conventionPluginScript.text.contains("options.encoding = 'UTF-8'") || conventionPluginScript.text.contains('options.encoding = "UTF-8"')
assertContainsEncodingConfig(conventionPluginScript, scriptDsl, 'UTF-8')
conventionPluginScript.text.contains(TextUtil.toPlatformLineSeparators('''
java {
withSourcesJar()
Expand Down Expand Up @@ -209,6 +209,29 @@ Root project 'webinar-parent'
failure.assertHasCause("There were failing tests.")
}

private static void assertContainsEncodingConfig(TestFile buildScript, BuildInitDsl dsl, String encoding) {
def text = buildScript.text
if (dsl == BuildInitDsl.GROOVY) {
assert text.contains(TextUtil.toPlatformLineSeparators("""
tasks.withType(JavaCompile) {
options.encoding = '$encoding'
}
tasks.withType(Javadoc) {
options.encoding = '$encoding'
}"""))
} else {
assert text.contains(TextUtil.toPlatformLineSeparators("""
tasks.withType<JavaCompile>() {
options.encoding = "$encoding"
}
tasks.withType<Javadoc>() {
options.encoding = "$encoding"
}"""))
}
}

private static void assertContainsPublishingConfig(TestFile buildScript, BuildInitDsl dsl, String indent = "", List<String> additionalArchiveTasks = []) {
def text = buildScript.text
if (dsl == BuildInitDsl.GROOVY) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ private void compilerSettings(MavenProject project, BuildScriptBuilder builder)
String encoding = (String) project.getProperties().get("project.build.sourceEncoding");
if (StringUtils.isNotEmpty(encoding)) {
builder.taskPropertyAssignment(null, "JavaCompile", "options.encoding", encoding);
builder.taskPropertyAssignment(null, "Javadoc", "options.encoding", encoding);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ gradle run
And the 'dependencies' report shows the dependency substitution in action:

```
gradle dependencies --configuration runtimeClasspath
gradle app:dependencies --configuration runtimeClasspath
```

```
runtimeClasspath - Runtime classpath of source set 'main'.
+--- org.sample:number-utils:1.0 -> project :number-utils
\--- org.sample:string-utils:1.0 -> project :string-utils
\--- org.apache.commons:commons-lang3:3.4
\--- org.apache.commons:commons-lang3:3.12.0
```

== Switching to use binary dependency
Expand Down Expand Up @@ -69,28 +69,28 @@ Note that the `number-utils` dependency is still satisfied by the included build
The 'dependencies' report shows the dependency substitution in action:

```
gradle dependencies --configuration runtimeClasspath
gradle app:dependencies --configuration runtimeClasspath
```

```
runtimeClasspath - Runtime classpath of source set 'main'.
+--- org.sample:number-utils:1.0 -> project :number-utils
\--- org.sample:string-utils:1.0
\--- org.apache.commons:commons-lang3:3.4
\--- org.apache.commons:commons-lang3:3.12.0
```

== Including an external library as a submodule

The power of this configuration can be demonstrated by adding the external 'commons-lang' build directly to the composite.

```
git clone http://git-wip-us.apache.org/repos/asf/commons-lang.git modules/commons-lang --branch master --depth 1
git clone http://gitbox.apache.org/repos/asf/commons-lang.git modules/commons-lang --branch rel/commons-lang-3.12.0 --depth 1
gradle --project-dir modules/commons-lang init
gradle run
```

You can see the external transitive dependency `commons-lang` being replaced with the local project dependency by running:

```
gradle dependencies --configuration compile
gradle app:dependencies --configuration runtimeClasspath
```
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ dependencies {

repositories {
maven {
url project.file("../../local-repo")
url project.file("../local-repo")
}
mavenCentral()
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
tasks.register('publishDeps') {
dependsOn gradle.includedBuilds*.task(':publishIvyPublicationToIvyRepository')
dependsOn gradle.includedBuilds*.task(':publishMavenPublicationToMavenRepository')
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,10 @@ plugins {
group "org.sample"
version "1.0"

repositories {
ivy {
name 'localrepo'
url file("../../../local-repo")
}
}

publishing {
repositories {
maven {
url file("../../../local-repo")
url file("../../local-repo")
}
}
publications {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,17 @@ group "org.sample"
version "1.0"

dependencies {
implementation "org.apache.commons:commons-lang3:3.4"
implementation "org.apache.commons:commons-lang3:3.12.0"
}

repositories {
maven {
name 'localrepo'
url file("../../../local-repo")
}
mavenCentral()
}

publishing {
repositories {
maven {
url file("../../../local-repo")
url file("../../local-repo")
}
}
publications {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ dependencies {

repositories {
maven {
url = uri(project.file("../../local-repo"))
url = uri(project.file("../local-repo"))
}
mavenCentral()
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,10 @@ plugins {
group = "org.sample"
version = "1.0"

repositories {
ivy {
name = "localrepo"
url = uri(file("../../../local-repo"))
}
}

publishing {
repositories {
ivy {
setUrl(file("../../../local-repo"))
maven {
setUrl(file("../../local-repo"))
}
}
publications {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,17 @@ group = "org.sample"
version = "1.0"

dependencies {
implementation("org.apache.commons:commons-lang3:3.4")
implementation("org.apache.commons:commons-lang3:3.12.0")
}

repositories {
maven {
name = "localrepo"
url = uri(file("../../../local-repo"))
}
mavenCentral()
}


publishing {
repositories {
maven {
setUrl(file("../../../local-repo"))
setUrl(file("../../local-repo"))
}
}
publications {
Expand Down

0 comments on commit 270f942

Please sign in to comment.