question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Plugin not always triggers scala classes rebuild.

See original GitHub issue

Steps to reproduce.

git clone git@github.com:michey/sbt-example.git
cd sbt-example
git checkout 1.0.0-branch
cd external-iface 
sbt publishLocal
git checkout 2.0.0-branch
sbt publishLocal

Successful case:

cd ../app
git checkout 1.0.0-branch
sbt compile
# works good. (expected result)

Failed case

git checkout 2.0.0-branch
sbt compile
# also works. (unexpected result)

Expected result: Compilation in 2.0.0-branch should fails because proto file has one less field and scala code tries to call constructor with two parameters.

Known workaround:

git checkout 2.0.0-branch
sbt clean
sbt compile

Diff between 1.0.0-branch and 2.0.0-branch

diff --git a/app/build.sbt b/app/build.sbt
index 01e2f26..6a5a63a 100644
--- a/app/build.sbt
+++ b/app/build.sbt
@@ -18,7 +18,7 @@ lazy val exampleProtobuf =
       PB.protocVersion := "3.17.3",
       libraryDependencies ++= Seq(
         "com.thesamet.scalapb" %% "scalapb-runtime" % scalapb.compiler.Version.scalapbVersion % "protobuf",
-        "acme" %% "external-iface" % "1.0.0" % "protobuf-src" intransitive(),
+        "acme" %% "external-iface" % "2.0.0" % "protobuf-src" intransitive(),
       ),
       Compile / PB.targets := Seq(
         scalapb.gen() -> (Compile / sourceManaged).value
diff --git a/external-iface/build.sbt b/external-iface/build.sbt
index faabb74..4af7277 100644
--- a/external-iface/build.sbt
+++ b/external-iface/build.sbt
@@ -2,4 +2,3 @@ name := "external-iface"
 scalaVersion := "2.13.7"
 organization := "acme"
 Compile / unmanagedResourceDirectories += baseDirectory.value / "protobuf"
-
diff --git a/external-iface/protobuf/iface/experimentation_service.proto b/external-iface/protobuf/iface/experimentation_service.proto
index 126d105..904c963 100644
--- a/external-iface/protobuf/iface/experimentation_service.proto
+++ b/external-iface/protobuf/iface/experimentation_service.proto
@@ -5,5 +5,5 @@ option java_package = "iface";
 
 message Message {
   string first_field = 1;
-  string second_field = 2;
+//  string second_field = 2;
 }
diff --git a/external-iface/version.sbt b/external-iface/version.sbt
index 4b6a8b5..b547370 100644
--- a/external-iface/version.sbt
+++ b/external-iface/version.sbt
@@ -1 +1 @@
-ThisBuild / version := "1.0.0"
\ No newline at end of file
+ThisBuild / version := "2.0.0"
\ No newline at end of file

Summary: As I can see, sbt updates jar with proto files, sbt-protoc plugin unpacks this proto file in the right place, but plugin do not regenerate scala classes.

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:2
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
micheycommented, May 8, 2022

I’ve dug a little bit deeper and found that this problem is not related to sbt-protoc plugin. This behavior is related to these changes in sbt. https://github.com/sbt/sbt/pull/5344 sbt devs decide to implement “reproducible builds” through setting all mtime in jars to the fixed value. After the plugin unarchives these sources from jars we get protoc files with the same date for different versions. If you do not need this feature in your build pipelines you can easily opt-out https://github.com/sbt/sbt/pull/6237 You still have a chance to meet this problem if you have protoc files with the same mtime across different versions. But the chance is extremely low. ¯\_(ツ)_/¯

TL;DR: If your scala classes are not updating after changing the dependency version try to add ThisBuild / packageTimestamp := Package.keepTimestamps to your build.sbt on the publishing side.

0reactions
thesametcommented, Sep 10, 2022

It looks like there’s a reasonable workaround and there wasn’t any activity on this issue for quite a while, so closing.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Eclipse plugin rebuilds whole project even for minor changes
In my current project, it seems that changing pretty much anything in any file causes a long long recompile. This may be because...
Read more >
sbt always doing a full rebuild on spurious source changes
I put th following line at the end of my build.sbt: scalaSource in Compile := baseDirectory.value / "src". solved my problem, since due...
Read more >
sbt Reference Manual — Plugins
A plugin can define a sequence of sbt settings that are automatically added to all projects or that are explicitly declared for selected...
Read more >
Building a Scala Project with IntelliJ and sbt
Running the project​​ In the Tasks field, type ~run . The ~ causes sbt to rebuild and rerun the project when you save...
Read more >
Gradle 2.11 Release Notes
Adding the 'scala' plugin to your build will no longer create a 'scalaConsole' task to launch a Scala REPL from the Gradle build....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found