Skip to content
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

I have a new idea to incorporate this feature into the plugin for the purpose of using dynamic version dependencies #382

Open
zhangsg1234 opened this issue Jul 7, 2023 · 0 comments

Comments

@zhangsg1234
Copy link

zhangsg1234 commented Jul 7, 2023

The extension function of this plug-in I used and another plug-in can be extended to resolve the latest.release dependency version to the real version number when tagging, and restore the latest.release function when switching to the next snapshot version. I think it is necessary for the author to integrate this function into the plugin if he has time.

  1. import this plugin
id 'com.github.ben-manes.versions' version "${versions_plugin_version}"
  1. Naming rules for version number variable names
    Plugin version number:artifactID_plugin_version
    Regular version number:artifactID_version
  2. extended content
release{
    tasks.register('extractLatestReleaseProperty') {
        doLast {
            def directoryPath = "${buildDir}/latestReleaseProperty"
  
            def directory = new File(directoryPath)
            if (!directory.exists()) {
                directory.mkdirs()
                println "Directory created: $directoryPath"
            } else {
                println "Directory already exists: $directoryPath"
            }
            def outputFilePath = "${directoryPath}/report.txt"

            def properties = new Properties()
            properties.load(new FileInputStream('gradle.properties'))
      
            def propertyKeys = []
       
            properties.each { key, value ->
                if (value == 'latest.release') {
                    propertyKeys << key
                }
            }
            file(outputFilePath).write(propertyKeys.join('\n'))
            println "Latest release property extracted and saved to: $outputFilePath"
        }
    }
    tasks.register('changeRealVersion') {
        doLast {

            def latestReleaseList = new File("${buildDir}/latestReleaseProperty/report.txt")
                    .readLines();
            def realReleaseList = new File("${buildDir}/dependencyUpdates/report.txt").readLines().findAll { line ->
                line.contains(' - ')
            }
            Properties gradleProperties = new Properties()
            File propertiesFile = file("gradle.properties")
            gradleProperties.load(propertiesFile.newDataInputStream())
            latestReleaseList
                    .each { latestReleaseLine ->
                        realReleaseList.each { realReleaseLine ->
                            if (latestReleaseLine.contains('plugin')) {
                                if (realReleaseLine.contains(latestReleaseLine.replace('_plugin_version', '').replaceAll('_', '-'))) {
                                    gradleProperties.setProperty(latestReleaseLine, realReleaseLine.substring(realReleaseLine.lastIndexOf(":") + 1))
                                      return
                                }
                            } else {
                                if (realReleaseLine.contains(latestReleaseLine.replace('_version', '').replaceAll('_', '-'))) {
                                    gradleProperties.setProperty(latestReleaseLine, realReleaseLine.substring(realReleaseLine.lastIndexOf(":") + 1))
                                    return
                                }
                            }
                        }
                    }
            FileOutputStream output = new FileOutputStream(propertiesFile)
            gradleProperties.store(output, null)
            output.close()
        }
    }
tasks.register('recoveryLatestReleaseVersion') {
    doLast {
        def latestReleaseList = new File("${buildDir}/latestReleaseProperty/report.txt")
                .readLines();
        Properties gradleProperties = new Properties()
        File propertiesFile = file("gradle.properties")
        gradleProperties.load(propertiesFile.newDataInputStream())
        latestReleaseList.each { latestReleaseLine ->
            gradleProperties.setProperty(latestReleaseLine, 'latest.release')
        }
        FileOutputStream output = new FileOutputStream(propertiesFile)
        gradleProperties.store(output, null)
        output.close()
    }
}
    tasks {
        dependencyUpdates.dependsOn clean
		extractLatestReleaseProperty.dependsOn dependencyUpdates
		createScmAdapter.dependsOn extractLatestReleaseProperty
		unSnapshotVersion.dependsOn changeRealVersion
		updateVersion.dependsOn recoveryLatestReleaseVersion
		commitNewVersion.dependsOn clean

    }
}

These only contain my additions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant