Skip to content

Support relative paths in git.root #280

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

Merged
merged 1 commit into from
Mar 17, 2025
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 @@ -23,10 +23,13 @@ import org.ajoberstar.grgit.Tag
import org.gradle.api.plugins.JavaPlugin
import org.gradle.internal.impldep.com.amazonaws.util.Throwables
import org.gradle.testkit.runner.BuildResult
import org.gradle.testkit.runner.GradleRunner
import org.gradle.testkit.runner.TaskOutcome
import spock.lang.Ignore
import spock.lang.Unroll

import java.nio.file.Files

class ReleasePluginIntegrationSpec extends GitVersioningIntegrationTestKitSpec {
@Override
def setupBuild() {
Expand Down Expand Up @@ -1281,6 +1284,26 @@ nebula.release.features.immutableSnapshot.timestampPrecision=${precision.name()}
TimestampPrecision.MILLISECONDS | 17
}

def 'can use relative git.root'() {
given:
def subdir = new File(projectDir, 'subdir')
subdir.mkdirs()
['build.gradle', 'settings.gradle'].each {
def file = new File(projectDir, it)
Files.move(file.toPath(), new File(subdir, it).toPath())
}
new File(subdir, 'gradle.properties') << 'git.root=..'

when:
def result = GradleRunner.create()
.withProjectDir(subdir)
.withArguments('help', '-s')
.withPluginClasspath()
.build()

then:
result.task(':help').outcome == TaskOutcome.SUCCESS
}


private void replaceDevWithImmutableSnapshot() {
Expand Down
2 changes: 1 addition & 1 deletion src/main/groovy/nebula/plugin/release/ReleasePlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class ReleasePlugin implements Plugin<Project> {
@CompileDynamic
@Inject
ReleasePlugin(Project project, ExecOperations execOperations, ProviderFactory providerFactory) {
this.gitRoot = project.hasProperty('git.root') ? new File(project.property('git.root')) : project.rootProject.projectDir
this.gitRoot = project.hasProperty('git.root') ? project.file(project.property('git.root')) : project.rootProject.projectDir
this.gitBuildService = project.getGradle().getSharedServices().registerIfAbsent("gitBuildService", GitBuildService.class, spec -> {
spec.getParameters().getGitRootDir().set(gitRoot)
}).get()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class BaseReleasePlugin implements Plugin<Project> {

void apply(Project project) {
ReleasePluginExtension releasePluginExtension = project.extensions.create('release', ReleasePluginExtension, project)
File gitRoot = project.hasProperty('git.root') ? new File(project.property('git.root')) : project.rootProject.projectDir
File gitRoot = project.hasProperty('git.root') ? project.file(project.property('git.root')) : project.rootProject.projectDir
this.gitBuildService = project.getGradle().getSharedServices().registerIfAbsent("gitBuildService", GitBuildService.class, spec -> {
spec.getParameters().getGitRootDir().set(gitRoot)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class ReleasePluginExtension {
@CompileDynamic
@Inject
ReleasePluginExtension(Project project) {
File gitRoot = project.hasProperty('git.root') ? new File(project.property('git.root')) : project.rootProject.projectDir
File gitRoot = project.hasProperty('git.root') ? project.file(project.property('git.root')) : project.rootProject.projectDir
this.project = project
this.gitBuildService = project.getGradle().getSharedServices().registerIfAbsent("gitBuildService", GitBuildService.class, spec -> {
spec.getParameters().getGitRootDir().set(gitRoot)
Expand Down