Skip to content

Commit

Permalink
Merge pull request gradle#27264 Gradle-init source package property
Browse files Browse the repository at this point in the history
Fixes gradle#26219

The `gradle init` task behavior is changed in the following way:

- Source package can be specified via Gradle property
	- Using `org.gradle.buildinit.source.package` Gradle property users can specify package name to use for new projects generated by `gradle init`
	- The package name can be also empty, resulting in an [unnamed package](https://docs.oracle.com/javase/specs/jls/se8/html/jls-7.html#jls-7.4.2) for sources in subprojects that don't have their own package prefixes like `app` or `lib`
	- *Before: it was not possible to specify a the source package like that*

- When no source package is specified (neither via `init --package` nor via Gradle property)
	- Interactive dialog does request to provide it
	- A fixed package name `org.example` is used: `org.example.Main`
	- For multi-project builds, it's used as a prefix, e.g. `org.example.app.App`
	- *Before: uses had to answer an interactive question with a default value generated from project name, e.g. `my-toy-project` resulted in `my.toy.project` package default*

- For new projects, convention plugins generated in `buildSrc` or `build-logic`
	- Have a fixed name prefix `buildlogic`, e.g. `buildlogic.java-common-conventions.gradle.kts`
	- *Before: the source package name was used, e.g. `my.toy.project.java-common-conventions.gradle.kts`*

- For Maven-to-Gradle conversions, convention plugins generated in `buildSrc` or `build-logic`
	- Have a fixed name prefix `buildlogic`, e.g. `buildlogic.java-common-conventions.gradle.kts`
	- *Before: the Maven's root project group id was used, e.g. `my.toy.project.java-common-conventions.gradle.kts`*

Co-authored-by: Alex Semin <asemin@gradle.com>
  • Loading branch information
bot-gradle and alllex committed Dec 6, 2023
2 parents a22feef + 6996a69 commit 251ed1a
Show file tree
Hide file tree
Showing 42 changed files with 284 additions and 330 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,6 @@ class BuildInitInteractiveIntegrationTest extends AbstractInitIntegrationSpec {
}
handle.stdinPipe.write(TextUtil.platformLineSeparator.bytes)

// Enter a package name
ConcurrentTestUtil.poll(60) {
assert handle.standardOutput.contains("Source package (default: some.thing)")
}
handle.stdinPipe.write(("org.gradle.test" + TextUtil.platformLineSeparator).bytes)

// Enter a package name
ConcurrentTestUtil.poll(60) {
assert handle.standardOutput.contains("Enter target version of Java (min. 7) (default: ${Jvm.current().javaVersion.majorVersion})")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import org.gradle.buildinit.plugins.fixtures.ScriptDslFixture

class GroovyApplicationInitIntegrationTest extends AbstractJvmLibraryInitIntegrationSpec {

public static final String SAMPLE_APP_CLASS = "some/thing/App.groovy"
public static final String SAMPLE_APP_TEST_CLASS = "some/thing/AppTest.groovy"
public static final String SAMPLE_APP_CLASS = "org/example/App.groovy"
public static final String SAMPLE_APP_TEST_CLASS = "org/example/AppTest.groovy"

@Override
String subprojectName() { 'app' }
Expand All @@ -41,7 +41,7 @@ class GroovyApplicationInitIntegrationTest extends AbstractJvmLibraryInitIntegra
run("build")

then:
assertTestPassed("some.thing.AppTest", "application has a greeting")
assertTestPassed("org.example.AppTest", "application has a greeting")

when:
run("run")
Expand All @@ -68,7 +68,7 @@ class GroovyApplicationInitIntegrationTest extends AbstractJvmLibraryInitIntegra
run("build")

then:
assertTestPassed("some.thing.AppTest", "application has a greeting")
assertTestPassed("org.example.AppTest", "application has a greeting")

where:
scriptDsl << ScriptDslFixture.SCRIPT_DSLS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ class GroovyGradlePluginInitIntegrationTest extends AbstractInitIntegrationSpec
run('init', '--type', 'groovy-gradle-plugin', '--dsl', scriptDsl.id)

then:
subprojectDir.file("src/main/groovy").assertHasDescendants("some/thing/SomeThingPlugin.groovy")
subprojectDir.file("src/test/groovy").assertHasDescendants("some/thing/SomeThingPluginTest.groovy")
subprojectDir.file("src/functionalTest/groovy").assertHasDescendants("some/thing/SomeThingPluginFunctionalTest.groovy")
subprojectDir.file("src/main/groovy").assertHasDescendants("org/example/SomeThingPlugin.groovy")
subprojectDir.file("src/test/groovy").assertHasDescendants("org/example/SomeThingPluginTest.groovy")
subprojectDir.file("src/functionalTest/groovy").assertHasDescendants("org/example/SomeThingPluginFunctionalTest.groovy")

and:
commonJvmFilesGenerated(scriptDsl)
Expand All @@ -60,8 +60,8 @@ class GroovyGradlePluginInitIntegrationTest extends AbstractInitIntegrationSpec
run("build")

then:
assertTestPassed("some.thing.SomeThingPluginTest", "plugin registers task")
assertFunctionalTestPassed("some.thing.SomeThingPluginFunctionalTest", "can run task")
assertTestPassed("org.example.SomeThingPluginTest", "plugin registers task")
assertFunctionalTestPassed("org.example.SomeThingPluginFunctionalTest", "can run task")

where:
scriptDsl << ScriptDslFixture.SCRIPT_DSLS
Expand All @@ -75,9 +75,9 @@ class GroovyGradlePluginInitIntegrationTest extends AbstractInitIntegrationSpec
run('init', '--type', 'groovy-gradle-plugin', '--dsl', scriptDsl.id, '--incubating')

then:
subprojectDir.file("src/main/groovy").assertHasDescendants("some/thing/SomeThingPlugin.groovy")
subprojectDir.file("src/test/groovy").assertHasDescendants("some/thing/SomeThingPluginTest.groovy")
subprojectDir.file("src/functionalTest/groovy").assertHasDescendants("some/thing/SomeThingPluginFunctionalTest.groovy")
subprojectDir.file("src/main/groovy").assertHasDescendants("org/example/SomeThingPlugin.groovy")
subprojectDir.file("src/test/groovy").assertHasDescendants("org/example/SomeThingPluginTest.groovy")
subprojectDir.file("src/functionalTest/groovy").assertHasDescendants("org/example/SomeThingPluginFunctionalTest.groovy")

and:
commonJvmFilesGenerated(scriptDsl)
Expand All @@ -88,8 +88,8 @@ class GroovyGradlePluginInitIntegrationTest extends AbstractInitIntegrationSpec
run("build")

then:
assertTestPassed("some.thing.SomeThingPluginTest", "plugin registers task")
assertFunctionalTestPassed("some.thing.SomeThingPluginFunctionalTest", "can run task")
assertTestPassed("org.example.SomeThingPluginTest", "plugin registers task")
assertFunctionalTestPassed("org.example.SomeThingPluginFunctionalTest", "can run task")

where:
scriptDsl << ScriptDslFixture.SCRIPT_DSLS
Expand All @@ -107,8 +107,8 @@ class GroovyGradlePluginInitIntegrationTest extends AbstractInitIntegrationSpec
run("build")

then:
assertTestPassed("some.thing.SomeThingPluginTest", "plugin registers task")
assertFunctionalTestPassed("some.thing.SomeThingPluginFunctionalTest", "can run task")
assertTestPassed("org.example.SomeThingPluginTest", "plugin registers task")
assertFunctionalTestPassed("org.example.SomeThingPluginFunctionalTest", "can run task")

where:
scriptDsl << ScriptDslFixture.SCRIPT_DSLS
Expand All @@ -124,15 +124,15 @@ class GroovyGradlePluginInitIntegrationTest extends AbstractInitIntegrationSpec
run('check')

then:
assertTestPassed("some.thing.SomeThingPluginTest", "plugin registers task")
assertFunctionalTestPassed("some.thing.SomeThingPluginFunctionalTest", "can run task")
assertTestPassed("org.example.SomeThingPluginTest", "plugin registers task")
assertFunctionalTestPassed("org.example.SomeThingPluginFunctionalTest", "can run task")

when:
run('check', '--rerun-tasks')

then:
assertTestPassed("some.thing.SomeThingPluginTest", "plugin registers task")
assertFunctionalTestPassed("some.thing.SomeThingPluginFunctionalTest", "can run task")
assertTestPassed("org.example.SomeThingPluginTest", "plugin registers task")
assertFunctionalTestPassed("org.example.SomeThingPluginFunctionalTest", "can run task")

where:
scriptDsl << ScriptDslFixture.SCRIPT_DSLS
Expand All @@ -145,14 +145,14 @@ class GroovyGradlePluginInitIntegrationTest extends AbstractInitIntegrationSpec
run('init', '--type', 'groovy-gradle-plugin', '--dsl', scriptDsl.id)

// Copy functional test contents into default source set test
def projectTest = subprojectDir.file('src/test/groovy/some/thing/SomeThingPluginTest.groovy')
projectTest.text = subprojectDir.file('src/functionalTest/groovy/some/thing/SomeThingPluginFunctionalTest.groovy').text
def projectTest = subprojectDir.file('src/test/groovy/org/example/SomeThingPluginTest.groovy')
projectTest.text = subprojectDir.file('src/functionalTest/groovy/org/example/SomeThingPluginFunctionalTest.groovy').text

when:
run('check')

then:
assertTestPassed("some.thing.SomeThingPluginFunctionalTest", "can run task")
assertTestPassed("org.example.SomeThingPluginFunctionalTest", "can run task")

where:
scriptDsl << ScriptDslFixture.SCRIPT_DSLS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import org.gradle.buildinit.plugins.fixtures.ScriptDslFixture

class GroovyLibraryInitIntegrationTest extends AbstractJvmLibraryInitIntegrationSpec {

public static final String SAMPLE_LIBRARY_CLASS = "some/thing/Library.groovy"
public static final String SAMPLE_LIBRARY_TEST_CLASS = "some/thing/LibraryTest.groovy"
public static final String SAMPLE_LIBRARY_CLASS = "org/example/Library.groovy"
public static final String SAMPLE_LIBRARY_TEST_CLASS = "org/example/LibraryTest.groovy"

def "creates sample source if no source present with #scriptDsl build scripts"() {
when:
Expand All @@ -38,7 +38,7 @@ class GroovyLibraryInitIntegrationTest extends AbstractJvmLibraryInitIntegration
run("build")

then:
assertTestPassed("some.thing.LibraryTest", "someLibraryMethod returns true")
assertTestPassed("org.example.LibraryTest", "someLibraryMethod returns true")

where:
scriptDsl << ScriptDslFixture.SCRIPT_DSLS
Expand All @@ -59,7 +59,7 @@ class GroovyLibraryInitIntegrationTest extends AbstractJvmLibraryInitIntegration
run("build")

then:
assertTestPassed("some.thing.LibraryTest", "someLibraryMethod returns true")
assertTestPassed("org.example.LibraryTest", "someLibraryMethod returns true")

where:
scriptDsl << ScriptDslFixture.SCRIPT_DSLS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ import static org.gradle.buildinit.plugins.internal.modifiers.BuildInitDsl.KOTLI

class JavaApplicationInitIntegrationTest extends AbstractJvmLibraryInitIntegrationSpec {

public static final String SAMPLE_APP_CLASS = "some/thing/App.java"
public static final String SAMPLE_APP_TEST_CLASS = "some/thing/AppTest.java"
public static final String SAMPLE_APP_SPOCK_TEST_CLASS = "some/thing/AppTest.groovy"
public static final String SAMPLE_APP_CLASS = "org/example/App.java"
public static final String SAMPLE_APP_TEST_CLASS = "org/example/AppTest.java"
public static final String SAMPLE_APP_SPOCK_TEST_CLASS = "org/example/AppTest.groovy"

@Override
String subprojectName() { 'app' }
Expand Down Expand Up @@ -59,7 +59,7 @@ class JavaApplicationInitIntegrationTest extends AbstractJvmLibraryInitIntegrati
run("build")

then:
assertTestPassed("some.thing.AppTest", "appHasAGreeting")
assertTestPassed("org.example.AppTest", "appHasAGreeting")

when:
run("run")
Expand Down Expand Up @@ -88,7 +88,7 @@ class JavaApplicationInitIntegrationTest extends AbstractJvmLibraryInitIntegrati
when:
run('test')
then:
assertTestPassed("some.thing.AppTest", "appHasAGreeting")
assertTestPassed("org.example.AppTest", "appHasAGreeting")

where:
scriptDsl << ScriptDslFixture.SCRIPT_DSLS
Expand All @@ -105,7 +105,7 @@ class JavaApplicationInitIntegrationTest extends AbstractJvmLibraryInitIntegrati
succeeds('test')

then:
assertTestPassed("some.thing.AppTest", "appHasAGreeting")
assertTestPassed("org.example.AppTest", "appHasAGreeting")

where:
scriptDsl << ScriptDslFixture.SCRIPT_DSLS
Expand All @@ -127,7 +127,7 @@ class JavaApplicationInitIntegrationTest extends AbstractJvmLibraryInitIntegrati
run("build")

then:
assertTestPassed("some.thing.AppTest", "application has a greeting")
assertTestPassed("org.example.AppTest", "application has a greeting")

where:
scriptDsl << ScriptDslFixture.SCRIPT_DSLS
Expand All @@ -148,7 +148,7 @@ class JavaApplicationInitIntegrationTest extends AbstractJvmLibraryInitIntegrati
run("build")

then:
assertTestPassed("some.thing.AppTest", "appHasAGreeting")
assertTestPassed("org.example.AppTest", "appHasAGreeting")

where:
scriptDsl << ScriptDslFixture.SCRIPT_DSLS
Expand All @@ -169,7 +169,7 @@ class JavaApplicationInitIntegrationTest extends AbstractJvmLibraryInitIntegrati
run("build")

then:
assertTestPassed("some.thing.AppTest", "appHasAGreeting")
assertTestPassed("org.example.AppTest", "appHasAGreeting")

where:
scriptDsl << ScriptDslFixture.SCRIPT_DSLS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ class JavaGradlePluginInitIntegrationTest extends AbstractInitIntegrationSpec {
run('init', '--type', 'java-gradle-plugin', '--dsl', scriptDsl.id)

then:
subprojectDir.file("src/main/java").assertHasDescendants("some/thing/SomeThingPlugin.java")
subprojectDir.file("src/test/java").assertHasDescendants("some/thing/SomeThingPluginTest.java")
subprojectDir.file("src/functionalTest/java").assertHasDescendants("some/thing/SomeThingPluginFunctionalTest.java")
subprojectDir.file("src/main/java").assertHasDescendants("org/example/SomeThingPlugin.java")
subprojectDir.file("src/test/java").assertHasDescendants("org/example/SomeThingPluginTest.java")
subprojectDir.file("src/functionalTest/java").assertHasDescendants("org/example/SomeThingPluginFunctionalTest.java")

and:
commonJvmFilesGenerated(scriptDsl)
Expand All @@ -55,8 +55,8 @@ class JavaGradlePluginInitIntegrationTest extends AbstractInitIntegrationSpec {
run("build")

then:
assertTestPassed("some.thing.SomeThingPluginTest", "pluginRegistersATask")
assertFunctionalTestPassed("some.thing.SomeThingPluginFunctionalTest", "canRunTask")
assertTestPassed("org.example.SomeThingPluginTest", "pluginRegistersATask")
assertFunctionalTestPassed("org.example.SomeThingPluginFunctionalTest", "canRunTask")

where:
scriptDsl << ScriptDslFixture.SCRIPT_DSLS
Expand All @@ -70,9 +70,9 @@ class JavaGradlePluginInitIntegrationTest extends AbstractInitIntegrationSpec {
run('init', '--type', 'java-gradle-plugin', '--dsl', scriptDsl.id, '--incubating')

then:
subprojectDir.file("src/main/java").assertHasDescendants("some/thing/SomeThingPlugin.java")
subprojectDir.file("src/test/java").assertHasDescendants("some/thing/SomeThingPluginTest.java")
subprojectDir.file("src/functionalTest/java").assertHasDescendants("some/thing/SomeThingPluginFunctionalTest.java")
subprojectDir.file("src/main/java").assertHasDescendants("org/example/SomeThingPlugin.java")
subprojectDir.file("src/test/java").assertHasDescendants("org/example/SomeThingPluginTest.java")
subprojectDir.file("src/functionalTest/java").assertHasDescendants("org/example/SomeThingPluginFunctionalTest.java")

and:
commonJvmFilesGenerated(scriptDsl)
Expand All @@ -82,8 +82,8 @@ class JavaGradlePluginInitIntegrationTest extends AbstractInitIntegrationSpec {
run("build")

then:
assertTestPassed("some.thing.SomeThingPluginTest", "pluginRegistersATask")
assertFunctionalTestPassed("some.thing.SomeThingPluginFunctionalTest", "canRunTask")
assertTestPassed("org.example.SomeThingPluginTest", "pluginRegistersATask")
assertFunctionalTestPassed("org.example.SomeThingPluginFunctionalTest", "canRunTask")

where:
scriptDsl << ScriptDslFixture.SCRIPT_DSLS
Expand All @@ -99,15 +99,15 @@ class JavaGradlePluginInitIntegrationTest extends AbstractInitIntegrationSpec {
run('check')

then:
assertTestPassed("some.thing.SomeThingPluginTest", "pluginRegistersATask")
assertFunctionalTestPassed("some.thing.SomeThingPluginFunctionalTest", "canRunTask")
assertTestPassed("org.example.SomeThingPluginTest", "pluginRegistersATask")
assertFunctionalTestPassed("org.example.SomeThingPluginFunctionalTest", "canRunTask")

when:
run('check', '--rerun-tasks')

then:
assertTestPassed("some.thing.SomeThingPluginTest", "pluginRegistersATask")
assertFunctionalTestPassed("some.thing.SomeThingPluginFunctionalTest", "canRunTask")
assertTestPassed("org.example.SomeThingPluginTest", "pluginRegistersATask")
assertFunctionalTestPassed("org.example.SomeThingPluginFunctionalTest", "canRunTask")

where:
scriptDsl << ScriptDslFixture.SCRIPT_DSLS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ import static org.hamcrest.CoreMatchers.allOf

class JavaLibraryInitIntegrationTest extends AbstractJvmLibraryInitIntegrationSpec {

public static final String SAMPLE_LIBRARY_CLASS = "some/thing/Library.java"
public static final String SAMPLE_LIBRARY_TEST_CLASS = "some/thing/LibraryTest.java"
public static final String SAMPLE_SPOCK_LIBRARY_TEST_CLASS = "some/thing/LibraryTest.groovy"
public static final String SAMPLE_LIBRARY_CLASS = "org/example/Library.java"
public static final String SAMPLE_LIBRARY_TEST_CLASS = "org/example/LibraryTest.java"
public static final String SAMPLE_SPOCK_LIBRARY_TEST_CLASS = "org/example/LibraryTest.groovy"

def "defaults to Kotlin build scripts"() {
when:
Expand Down Expand Up @@ -57,7 +57,7 @@ class JavaLibraryInitIntegrationTest extends AbstractJvmLibraryInitIntegrationSp
run("build")

then:
assertTestPassed("some.thing.LibraryTest", "someLibraryMethodReturnsTrue")
assertTestPassed("org.example.LibraryTest", "someLibraryMethodReturnsTrue")

where:
scriptDsl << ScriptDslFixture.SCRIPT_DSLS
Expand All @@ -80,7 +80,7 @@ class JavaLibraryInitIntegrationTest extends AbstractJvmLibraryInitIntegrationSp
when:
run('test')
then:
assertTestPassed("some.thing.LibraryTest", "someLibraryMethodReturnsTrue")
assertTestPassed("org.example.LibraryTest", "someLibraryMethodReturnsTrue")

where:
scriptDsl << ScriptDslFixture.SCRIPT_DSLS
Expand All @@ -97,7 +97,7 @@ class JavaLibraryInitIntegrationTest extends AbstractJvmLibraryInitIntegrationSp
succeeds('test')

then:
assertTestPassed("some.thing.LibraryTest", "someLibraryMethodReturnsTrue")
assertTestPassed("org.example.LibraryTest", "someLibraryMethodReturnsTrue")

where:
scriptDsl << ScriptDslFixture.SCRIPT_DSLS
Expand All @@ -121,7 +121,7 @@ class JavaLibraryInitIntegrationTest extends AbstractJvmLibraryInitIntegrationSp
run("build")

then:
assertTestPassed("some.thing.LibraryTest", "someLibraryMethod returns true")
assertTestPassed("org.example.LibraryTest", "someLibraryMethod returns true")

where:
scriptDsl << ScriptDslFixture.SCRIPT_DSLS
Expand All @@ -144,7 +144,7 @@ class JavaLibraryInitIntegrationTest extends AbstractJvmLibraryInitIntegrationSp
run("build")

then:
assertTestPassed("some.thing.LibraryTest", "someLibraryMethodReturnsTrue")
assertTestPassed("org.example.LibraryTest", "someLibraryMethodReturnsTrue")

where:
scriptDsl << ScriptDslFixture.SCRIPT_DSLS
Expand All @@ -167,7 +167,7 @@ class JavaLibraryInitIntegrationTest extends AbstractJvmLibraryInitIntegrationSp
run("build")

then:
assertTestPassed("some.thing.LibraryTest", "someLibraryMethodReturnsTrue")
assertTestPassed("org.example.LibraryTest", "someLibraryMethodReturnsTrue")

where:
scriptDsl << ScriptDslFixture.SCRIPT_DSLS
Expand Down
Loading

0 comments on commit 251ed1a

Please sign in to comment.