Skip to content

Commit

Permalink
avoid having afterEvaluate in task AssemblyInfoPatcher
Browse files Browse the repository at this point in the history
it conflicts with task lazy initialization if the creation of task is after project evaluation

Change-Id: I0b06dd0d2e7976de80c26dc3dc9bd164e4c4a103
  • Loading branch information
ngyukman committed Mar 7, 2024
1 parent 58e4b8d commit da910e3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 24 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# gradle-msbuild-plugin changelog

# 4.6
### Fixed
* avoid having afterEvaluate in task AssemblyInfoPatcher

# 4.4
### Fixed
* Enable to parse project file using dotnet SDK 7+
Expand Down
32 changes: 10 additions & 22 deletions src/main/groovy/com/ullink/AssemblyInfoVersionPatcher.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -44,31 +44,19 @@ class AssemblyInfoVersionPatcher extends DefaultTask {
informationalVersion = project.getObjects().property(String)
fileVersion.set(project.provider ({ version }))
informationalVersion.set(project.provider ({ version }))

project.afterEvaluate {
if (!version) return
project.tasks.withType(Msbuild) { Msbuild task ->
for (def proj in task.projects.collect { e -> e.value }) {
def parsedFiles = files.get()

if (proj.getItems('Compile')?.intersect(parsedFiles)) {
project.logger.info("Found matching AssemblyInfo file, Task[${task.name}] will depend on Task[${this.name}]")
task.dependsOn this
return
}

if (proj.properties.MSBuildProjectFullPath && parsedFiles.contains(project.file(proj.properties.MSBuildProjectFullPath))) {
project.logger.info("Found matching project file, Task[${task.name}] will depend on Task[${this.name}]")
task.dependsOn this
return
}
}
}
}
enabled = false
}

private String versionValue
@Input
String version
String getVersion() {
return versionValue
}

void setVersion(String version) {
versionValue = version
enabled = version != null
}

@Input
final Property<String> fileVersion
Expand Down
7 changes: 5 additions & 2 deletions src/main/groovy/com/ullink/MsbuildPlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@ import org.gradle.language.base.plugins.LifecycleBasePlugin
class MsbuildPlugin implements Plugin<Project> {
void apply(Project project) {
project.pluginManager.apply(BasePlugin)
project.tasks.register('msbuild', Msbuild)

def assemblyInfoPatcher = project.tasks.register('assemblyInfoPatcher', AssemblyInfoVersionPatcher)
project.tasks.register('msbuild', Msbuild) {
dependsOn assemblyInfoPatcher
}
def cleanMsbuild = project.tasks.register('cleanMsbuild')
project.tasks.named(LifecycleBasePlugin.CLEAN_TASK_NAME).configure {
dependsOn cleanMsbuild
}
project.tasks.register('assemblyInfoPatcher', AssemblyInfoVersionPatcher)
}
}

0 comments on commit da910e3

Please sign in to comment.