-
Notifications
You must be signed in to change notification settings - Fork 386
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
Generate version information when publishing artifacts #1188
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import sbt._ | ||
import sbt.Keys._ | ||
|
||
/** | ||
* Generate version.conf and akka/kafka/Version.scala files based on the version setting. | ||
* | ||
* This was adapted from https://github.com/akka/akka/blob/v2.6.8/project/VersionGenerator.scala | ||
*/ | ||
object VersionGenerator { | ||
|
||
val settings: Seq[Setting[_]] = inConfig(Compile)( | ||
Seq( | ||
resourceGenerators += generateVersion(resourceManaged, _ / "version.conf", """|akka.kafka.version = "%s" | ||
|"""), | ||
sourceGenerators += generateVersion( | ||
sourceManaged, | ||
_ / "akka" / "kafka" / "Version.scala", | ||
"""|package akka.kafka | ||
| | ||
|object Version { | ||
| val current: String = "%s" | ||
|} | ||
|""" | ||
) | ||
) | ||
) | ||
|
||
def generateVersion(dir: SettingKey[File], locate: File => File, template: String) = Def.task[Seq[File]] { | ||
val file = locate(dir.value) | ||
val content = template.stripMargin.format(version.value) | ||
if (!file.exists || IO.read(file) != content) IO.write(file, content) | ||
Seq(file) | ||
} | ||
|
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't the
version.conf
file collide with others in a fat-jar scenario?I guess those could be merged.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If multiple artifacts contain
version.conf
files, users need to configure a merge strategy when using sbt-assembly, or they will get an error* like this:But since we are using a distinct key for alpakka-kafka version, it is safe to concat the files, as you guessed.
* I'm not sure why sbt-assembly is not handling all filenames ending in
.conf
as configuration files. Maybe it is worth to send a PR there too?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, merging
*.conf
files seems reasonable to me.An alternative for now would be to create a file named
akka-kafa-version.conf
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hum, "for now" implying that it is going to change in the future, right? If so, I would not bother to have another name, and then move to
version.conf
later. Users should be able to configure what to do pretty easily, so I don't see why to have extra steps here. But also, I don't have a strong opinion on that. My only concern is to handle multiple version files in Cinnamon in the future.Finally, I created a new issue in sbt-assembly: sbt/sbt-assembly#406. If they decide it make sense to support all
.conf
files out-of-the-box, I will submit a PR there, and users would only need to update sbt-assembly then.WDYT?