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

Generate version information when publishing artifacts #1188

Merged
merged 1 commit into from
Aug 24, 2020
Merged

Generate version information when publishing artifacts #1188

merged 1 commit into from
Aug 24, 2020

Conversation

marcospereira
Copy link
Contributor

Currently, the only way to get version information from alpakka-kafka artifacts is by reading its MANIFEST.MF file, which may be fragile when sbt-assembly or other fatjar packagers are used: the manifest can be lost, overridden by another one, or multiple artifacts may be using Implementation-Version key.

To overcome this problem, Akka, Play, and Lagom all package a version class containing such information. Therefore, no matter if the application using them is building a fatjar or not, the version information is consistently accessible.

This pull request brings Akka solution and creates both akka.kafka.Version class as well as a version.conf with a key that is less prone to conflict with another artifact.

Copy link
Member

@ennru ennru left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, with one question below.


val settings: Seq[Setting[_]] = inConfig(Compile)(
Seq(
resourceGenerators += generateVersion(resourceManaged, _ / "version.conf", """|akka.kafka.version = "%s"
Copy link
Member

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.

Copy link
Contributor Author

@marcospereira marcospereira Aug 21, 2020

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:

[error] 1 error was encountered during merge
[error] stack trace is suppressed; run last assembly for the full output
[error] (assembly) deduplicate: different file contents found in the following:
[error] /Users/marcospereira/.ivy2/local/com.typesafe.akka/akka-stream-kafka_2.13/2.0.4+12-31cf63dd/jars/akka-stream-kafka_2.13.jar:version.conf
[error] /Users/marcospereira/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/com/typesafe/akka/akka-actor_2.13/2.5.30/akka-actor_2.13-2.5.30.jar:version.conf

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?

Copy link
Member

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.

Copy link
Contributor Author

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?

Copy link
Contributor

@seglo seglo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ennru ennru added this to the 2.0.5 milestone Aug 24, 2020
@ennru ennru merged commit c878803 into akka:master Aug 24, 2020
@marcospereira marcospereira deleted the build/version-generator branch August 24, 2020 22:11
@gurgec
Copy link

gurgec commented Oct 15, 2020

Hi All. I am not sure I wrote to the right place but this commit is not working in shaded jar. We have an application that we use akka and akka-streams together and when we try to run our app We got following exception since we have only 'akka.kafka.version' in our version.conf instead of 'akka.version'.
Maybe we can keep both. I resolved this issue by changing version to 2.0.4. Thank you.

No configuration setting found for key 'akka.version'
        at com.typesafe.config.impl.SimpleConfig.findKeyOrNull(SimpleConfig.java:156)
        at com.typesafe.config.impl.SimpleConfig.findOrNull(SimpleConfig.java:174)
        at com.typesafe.config.impl.SimpleConfig.findOrNull(SimpleConfig.java:180)
        at com.typesafe.config.impl.SimpleConfig.find(SimpleConfig.java:188)
        at com.typesafe.config.impl.SimpleConfig.find(SimpleConfig.java:193)
        at com.typesafe.config.impl.SimpleConfig.getString(SimpleConfig.java:250)
        at akka.actor.ActorSystem$Settings.<init>(ActorSystem.scala:396)
        at akka.actor.ActorSystemImpl.<init>(ActorSystem.scala:813)
        at akka.actor.ActorSystem$.apply(ActorSystem.scala:272)
        at akka.actor.ActorSystem$.apply(ActorSystem.scala:316)
        at akka.actor.ActorSystem$.apply(ActorSystem.scala:290)
        at akka.actor.ActorSystem$.create(ActorSystem.scala:213)
        at akka.actor.ActorSystem.create(ActorSystem.scala)
        at com.location.App.main(App.java:25)

@seglo
Copy link
Contributor

seglo commented Oct 15, 2020

It's not clear from the stack trace that this is related to Alpakka Kafka itself since the issue is resolving akka.version. Are you creating a fat jar? Some effort may be required to merge configuration correctly. There's some discussion in the akka documentation: https://doc.akka.io/docs/akka/current/additional/packaging.html .

@gurgec
Copy link

gurgec commented Oct 15, 2020

It's not clear from the stack trace that this is related to Alpakka Kafka itself since the issue is resolving akka.version. Are you creating a fat jar? Some effort may be required to merge configuration correctly. There's some discussion in the akka documentation: https://doc.akka.io/docs/akka/current/additional/packaging.html .

Yes. I am creating fat jar and I am following the instructions in packaging doc. I opened the jar and saw we do not have 'akka.version' in version.conf. When I downgraded to 2.0.4 I have 'akka.version' and everything works fine.

@marcospereira
Copy link
Contributor Author

How are you packaging the fat jar? Is it using sbt-assembly? If that is the case, you have to configure it to use MergeStrategy.concat for version.conf files:

https://github.com/sbt/sbt-assembly#merge-strategy

@gurgec
Copy link

gurgec commented Oct 16, 2020

How are you packaging the fat jar? Is it using sbt-assembly? If that is the case, you have to configure it to use MergeStrategy.concat for version.conf files:

https://github.com/sbt/sbt-assembly#merge-strategy

I am using gradle. I will have a look at MergeStrategy.concat. Thank you.

@ebrurak
Copy link

ebrurak commented Oct 23, 2020

Hi all,

I encountered same problem of 'akka.version' as @gurgec with alpakka-kafka 2.0.5. Everything works well when I downgraded to 2.0.4.
I create fat jar with maven as mentionned in the akka documentation.

Resolved by merging version.conf as well as reference.conf in our case.

https://doc.akka.io/docs/akka/current/additional/packaging.html

@ennru
Copy link
Member

ennru commented Oct 27, 2020

As described above: You need to configure your fat jar tooling to merge the version.conf files from the multiple jars.

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

Successfully merging this pull request may close these issues.

5 participants