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

Cannot handle ${packaging.type} variable #3618

Closed
Iacob opened this issue Oct 6, 2017 · 40 comments
Closed

Cannot handle ${packaging.type} variable #3618

Iacob opened this issue Oct 6, 2017 · 40 comments

Comments

@Iacob
Copy link

Iacob commented Oct 6, 2017

steps

Add following line to build.sbt

libraryDependencies += "org.glassfish.jersey.core" % "jersey-server" % "2.26"

problem

When building the project, sbt throwing the following error message and quit:

Error:Error while importing SBT project:
[warn] 	[FAILED     ] javax.ws.rs#javax.ws.rs-api;2.1!javax.ws.rs-api.${packaging.type}:  (0ms)

expectation

${packaging.type} should be correctly handled, the correct value is "jar".

notes

using sbt 1.0.2

@eed3si9n
Copy link
Member

eed3si9n commented Oct 7, 2017

Here's a workaround that you can add to `build.sbt`:
val workaround = {
  sys.props += "packaging.type" -> "jar"
  ()
}

I found this on ronmamo/reflections#169

Edit: See an improved workaround #3618 (comment)

@Iacob
Copy link
Author

Iacob commented Oct 7, 2017

Thank you very much, that's solved my problem.

@xmariachi
Copy link

This workaround works strangely for me: first time does not, second time works. This is very ugly - especially for a Docker installation I'm preparing.

I apply the workaround proposed here.

My dependency line:

"javax.ws.rs" % "javax.ws.rs-api" % "2.1"

I begin with non-existent ~/.ivy2/cache/javax.ws.rs/javax.ws.rs-api directory.

First time I run it, I still get the error:

$ sbt assembly 
... 
sbt.librarymanagement.ResolveException: download failed: javax.ws.rs#javax.ws.rs-api;2.1!javax.ws.rs-api.${packaging.type}

So it fails, but it creates some files in the corresponding directory:

$ ls   ~/.ivy2/cache/javax.ws.rs/javax.ws.rs-api/
ivy-2.1.xml
ivy-2.1.xml.original
ivydata-2.1.properties

And, the next run of sbt assembly, it goes through, downloading the files into jars dir inside the above directory:

$ ls   ~/.ivy2/cache/javax.ws.rs/javax.ws.rs-api/jars
javax.ws.rs-api-2.1.jar

The same happens with sbt package (just in case it has to do with assembly plugin).
Any hints or ideas?

gavares pushed a commit to gavares/Ammonite that referenced this issue May 29, 2018
Numerous build systems which rely on ivy for artifact resolution
currently fail to pull artifacts which use the `{packaging.type}`
feature available for use in maven pom files.

Recent builds of Coursier do not suffer from this bug.

This change updates the version of coursier from 1.0.0 -> 1.0.3 to pull
in the fix for this issue.

For reference, some tickets related to the ivy issue:

* sbt/sbt#3618
* gradle/gradle#3065
* https://github.com/jax-rs/api/pull/576
gavares pushed a commit to gavares/Ammonite that referenced this issue May 30, 2018
Numerous build systems which rely on ivy for artifact resolution
currently fail to pull artifacts which use the `{packaging.type}`
feature available for use in maven pom files.

Recent builds of Coursier do not suffer from this bug.

This change updates the version of coursier from 1.0.0 -> 1.1.0-M4 to pull
in the fix for this issue. As part of that change, references to
scalaz were removed from the core but left in some of the testing code.

For reference, some tickets related to the ivy issue:

* sbt/sbt#3618
* gradle/gradle#3065
* https://github.com/jax-rs/api/pull/576
@ablx
Copy link

ablx commented Jul 3, 2018

This still happens in sbt 1.1.0 - any version available where this is fixed?

@ablx
Copy link

ablx commented Aug 15, 2018

@eed3si9n this bug is not fixed (see comment from @xmariachi )
Can you please reopen it?

@dougjanzen
Copy link

Adding an explicit dependency on javax.ws.rs-api like this worked for me:

libraryDependencies += "javax.ws.rs" % "javax.ws.rs-api" % "2.1" artifacts( Artifact("javax.ws.rs-api", "jar", "jar"))

I tried the workaround mentioned earlier that sets sys.props and also found that it worked sometimes but not always.

@ablx
Copy link

ablx commented Aug 15, 2018

Thanks @dougjanzen
I "fixed" it by calling sbt compile twice in gitlab-ci, however I'd prefer a working version :-)

@chrisalbright
Copy link

chrisalbright commented Sep 20, 2018

Getting this when adding libraryDependencies += "org.apache.kafka" %% "kafka-streams-scala" % "2.0.0" withSources() to my project.

Workaround from above works for me - but definitely sucks.

[warn] 	::::::::::::::::::::::::::::::::::::::::::::::
[warn] 	::              FAILED DOWNLOADS            ::
[warn] 	:: ^ see resolution messages for details  ^ ::
[warn] 	::::::::::::::::::::::::::::::::::::::::::::::
[warn] 	:: javax.ws.rs#javax.ws.rs-api;2.1!javax.ws.rs-api.${packaging.type}
[warn] 	::::::::::::::::::::::::::::::::::::::::::::::
[error] sbt.librarymanagement.ResolveException: download failed: javax.ws.rs#javax.ws.rs-api;2.1!javax.ws.rs-api.${packaging.type}
[error] 	at sbt.internal.librarymanagement.IvyActions$.resolveAndRetrieve(IvyActions.scala:332)
[error] 	at sbt.internal.librarymanagement.IvyActions$.$anonfun$updateEither$1(IvyActions.scala:208)
[error] 	at sbt.internal.librarymanagement.IvySbt$Module.$anonfun$withModule$1(Ivy.scala:239)
[error] 	at sbt.internal.librarymanagement.IvySbt.$anonfun$withIvy$1(Ivy.scala:204)
[error] 	at sbt.internal.librarymanagement.IvySbt.sbt$internal$librarymanagement$IvySbt$$action$1(Ivy.scala:70)
[error] 	at sbt.internal.librarymanagement.IvySbt$$anon$3.call(Ivy.scala:77)
[error] 	at xsbt.boot.Locks$GlobalLock.withChannel$1(Locks.scala:95)
[error] 	at xsbt.boot.Locks$GlobalLock.xsbt$boot$Locks$GlobalLock$$withChannelRetries$1(Locks.scala:80)
[error] 	at xsbt.boot.Locks$GlobalLock$$anonfun$withFileLock$1.apply(Locks.scala:99)
[error] 	at xsbt.boot.Using$.withResource(Using.scala:10)
[error] 	at xsbt.boot.Using$.apply(Using.scala:9)
[error] 	at xsbt.boot.Locks$GlobalLock.ignoringDeadlockAvoided(Locks.scala:60)
[error] 	at xsbt.boot.Locks$GlobalLock.withLock(Locks.scala:50)
[error] 	at xsbt.boot.Locks$.apply0(Locks.scala:31)
[error] 	at xsbt.boot.Locks$.apply(Locks.scala:28)
[error] 	at sbt.internal.librarymanagement.IvySbt.withDefaultLogger(Ivy.scala:77)
[error] 	at sbt.internal.librarymanagement.IvySbt.withIvy(Ivy.scala:199)
[error] 	at sbt.internal.librarymanagement.IvySbt.withIvy(Ivy.scala:196)
[error] 	at sbt.internal.librarymanagement.IvySbt$Module.withModule(Ivy.scala:238)
[error] 	at sbt.internal.librarymanagement.IvyActions$.updateEither(IvyActions.scala:193)
[error] 	at sbt.librarymanagement.ivy.IvyDependencyResolution.update(IvyDependencyResolution.scala:20)
[error] 	at sbt.librarymanagement.DependencyResolution.update(DependencyResolution.scala:56)
[error] 	at sbt.internal.LibraryManagement$.resolve$1(LibraryManagement.scala:45)
[error] 	at sbt.internal.LibraryManagement$.$anonfun$cachedUpdate$12(LibraryManagement.scala:93)
[error] 	at sbt.util.Tracked$.$anonfun$lastOutput$1(Tracked.scala:68)
[error] 	at sbt.internal.LibraryManagement$.$anonfun$cachedUpdate$19(LibraryManagement.scala:106)
[error] 	at scala.util.control.Exception$Catch.apply(Exception.scala:224)
[error] 	at sbt.internal.LibraryManagement$.$anonfun$cachedUpdate$11(LibraryManagement.scala:106)
[error] 	at sbt.internal.LibraryManagement$.$anonfun$cachedUpdate$11$adapted(LibraryManagement.scala:89)
[error] 	at sbt.util.Tracked$.$anonfun$inputChanged$1(Tracked.scala:149)
[error] 	at sbt.internal.LibraryManagement$.cachedUpdate(LibraryManagement.scala:120)
[error] 	at sbt.Classpaths$.$anonfun$updateTask$5(Defaults.scala:2550)
[error] 	at scala.Function1.$anonfun$compose$1(Function1.scala:44)
[error] 	at sbt.internal.util.$tilde$greater.$anonfun$$u2219$1(TypeFunctions.scala:40)
[error] 	at sbt.std.Transform$$anon$4.work(System.scala:67)
[error] 	at sbt.Execute.$anonfun$submit$2(Execute.scala:269)
[error] 	at sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:16)
[error] 	at sbt.Execute.work(Execute.scala:278)
[error] 	at sbt.Execute.$anonfun$submit$1(Execute.scala:269)
[error] 	at sbt.ConcurrentRestrictions$$anon$4.$anonfun$submitValid$1(ConcurrentRestrictions.scala:178)
[error] 	at sbt.CompletionService$$anon$2.call(CompletionService.scala:37)
[error] 	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
[error] 	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
[error] 	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
[error] 	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
[error] 	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
[error] 	at java.lang.Thread.run(Thread.java:745)
[error] (update) sbt.librarymanagement.ResolveException: download failed: javax.ws.rs#javax.ws.rs-api;2.1!javax.ws.rs-api.${packaging.type}

@mrt181
Copy link

mrt181 commented Sep 25, 2018

I have the same error with sbt 1.2.3 when depending on kafka-streams

@eed3si9n eed3si9n reopened this Sep 27, 2018
@eed3si9n
Copy link
Member

I wonder if there's some evaluation ordering issue.

Could you try

libraryDependencies += {
  sys.props += "packaging.type" -> "jar"
  "org.apache.kafka" %% "kafka-streams-scala" % "2.0.0" withSources() 
}

@eed3si9n
Copy link
Member

eed3si9n commented Sep 27, 2018

The other workaround might be to make an ad-hoc AutoPlugin.

project/PackagingTypePlugin.scala

import sbt._

object PackagingTypePlugin extends AutoPlugin {
  override val buildSettings = {
    sys.props += "packaging.type" -> "jar"
    Nil
  }
}

The above works for me.

@h5chauhan
Copy link

h5chauhan commented Sep 29, 2018

@eed3si9n

import sbt._ object PackagingTypePlugin extends AutoPlugin { override val buildSettings = { sys.props += "packaging.type" -> "jar" Nil } }

/code/build.sbt:3: error: illegal start of simple expression
object PackagingTypePlugin extends AutoPlugin {
^
[error] Error parsing expression. Ensure that there are no blank lines within a setting.

@eed3si9n
Copy link
Member

@l0n3r4n83r You need to create it at project/PackagingTypePlugin.scala, not build.sbt.

@vitojeng
Copy link

project/PackagingTypePlugin.scala

import sbt._

object PackagingTypePlugin extends AutoPlugin {
  override val buildSettings = {
    sys.props += "packaging.type" -> "jar"
    Nil
  }
}

The above works for me.

@eed3si9n This work for me, too. Thanks!

@eed3si9n
Copy link
Member

ok. I am closing this issue then.

@edmondop
Copy link

edmondop commented Jan 17, 2019

@lavrov what sort of workaround do you have for your CI?

@erikvanoosten
Copy link

erikvanoosten commented Jan 17, 2019

@halfninja Thanks! Unfortunately it doesn't help. Coursier insists on downloading the jakarta.ws.rs pom (and only the pom), even though it is not needed.

This is the workaround we use in our CI (bash) script:

if [ ! -f ~/.m2/repository/javax/ws/rs/javax.ws.rs-api/2.1/javax.ws.rs-api-2.1.pom ]; then
  mkdir -p ~/.m2/repository/javax/ws/rs/javax.ws.rs-api/2.1
  curl -k http://central.maven.org/maven2/javax/ws/rs/javax.ws.rs-api/2.1/javax.ws.rs-api-2.1.pom > ~/.m2/repository/javax/ws/rs/javax.ws.rs-api/2.1/javax.ws.rs-api-2.1.pom
fi

Don't forget to update the link so that it points to your local maven proxy.

@lavrov
Copy link

lavrov commented Jan 18, 2019

@lavrov what sort of workaround do you have for your CI?

@edmondo1984
-Dpackaging.type=jar in .sbtopts

@tpanagos
Copy link

tpanagos commented Feb 8, 2019

libraryDependencies ++= Seq(
"org.apache.jclouds.api" % "filesystem" % "2.1.1",
"org.apache.tika" % "tika-parsers" % "1.20",
"jakarta.ws.rs" % "jakarta.ws.rs-api" % "2.1.4"
).map(_ exclude("javax.ws.rs", "javax.ws.rs-api"))

I tried all the above. Putting this (or something like it) into my build.sbt file is the only work-around that fixed the problem BOTH my local build (OSX) and on CircleCI (Linux).

@levinson
Copy link

levinson commented Jun 7, 2019

As a workaround exclude the busted dependency:

    excludeDependencies ++= Seq(
      // workaround for https://github.com/sbt/sbt/issues/3618
      // include "jakarta.ws.rs" % "jakarta.ws.rs-api" instead
      ExclusionRule("javax.ws.rs", "javax.ws.rs-api"),
    )

... and add a working alternative:

libraryDependencies += "jakarta.ws.rs" % "jakarta.ws.rs-api" % "2.1.5"

@MartensYM
Copy link

As a workaround exclude the busted dependency:

    excludeDependencies ++= Seq(
      // workaround for https://github.com/sbt/sbt/issues/3618
      // include "jakarta.ws.rs" % "jakarta.ws.rs-api" instead
      ExclusionRule("javax.ws.rs", "javax.ws.rs-api"),
    )

... and add a working alternative:

libraryDependencies += "jakarta.ws.rs" % "jakarta.ws.rs-api" % "2.1.5"

This worked for me, thanks!

@ches
Copy link
Contributor

ches commented Jul 2, 2019

It sounds like upstream Ivy might have fixed this in a proper way in Ivy 2.5.0-rc1. sbt's Ivy fork appears woefully far behind that, and it's not likely to be a trivial backport 😞

@anilkumarmyla
Copy link
Contributor

sbt 1.3.x switches from ivy to coursier for dependency management, so expect this to be resolved in 1.3.x series

@VillenaDeveloper
Copy link

As a workaround exclude the busted dependency:

    excludeDependencies ++= Seq(
      // workaround for https://github.com/sbt/sbt/issues/3618
      // include "jakarta.ws.rs" % "jakarta.ws.rs-api" instead
      ExclusionRule("javax.ws.rs", "javax.ws.rs-api"),
    )

... and add a working alternative:

libraryDependencies += "jakarta.ws.rs" % "jakarta.ws.rs-api" % "2.1.5"

Thanks for this. Good workaround.

@anilkumarmyla
Copy link
Contributor

This is fixed in sbt-1.3.0 unless you've opted out of coursier

@eed3si9n
Copy link
Member

eed3si9n commented Sep 6, 2019

Confirmed using sbt 1.3.0:

sbt:foo> update
[info] Updating
https://repo1.maven.org/maven2/org/glassfish/jersey/core/jersey-server/2.26/jersey-server-2.26.pom
  100.0% [##########] 10.8 KiB (24.4 KiB / s)
https://repo1.maven.org/maven2/org/glassfish/jersey/project/2.26/project-2.26.pom
  100.0% [##########] 83.8 KiB (829.2 KiB / s)
https://repo1.maven.org/maven2/org/glassfish/hk2/hk2-bom/2.5.0-b42/hk2-bom-2.5.0-b42.pom
  100.0% [##########] 16.0 KiB (380.2 KiB / s)
https://repo1.maven.org/maven2/org/glassfish/jersey/core/jersey-client/2.26/jersey-client-2.26.pom
  100.0% [##########] 7.2 KiB (164.3 KiB / s)
https://repo1.maven.org/maven2/org/glassfish/jersey/media/jersey-media-jaxb/2.26/jersey-media-jaxb-2.26.pom
  100.0% [##########] 6.6 KiB (106.4 KiB / s)
https://repo1.maven.org/maven2/org/glassfish/hk2/external/javax.inject/2.5.0-b42/javax.inject-2.5.0-b42.pom
  100.0% [##########] 6.3 KiB (78.3 KiB / s)
https://repo1.maven.org/maven2/org/glassfish/jersey/core/jersey-common/2.26/jersey-common-2.26.pom
  100.0% [##########] 9.6 KiB (115.6 KiB / s)
https://repo1.maven.org/maven2/javax/ws/rs/javax.ws.rs-api/2.1/javax.ws.rs-api-2.1.pom
  100.0% [##########] 29.5 KiB (297.9 KiB / s)
https://repo1.maven.org/maven2/org/glassfish/hk2/external/2.5.0-b42/external-2.5.0-b42.pom
  100.0% [##########] 2.8 KiB (64.5 KiB / s)
https://repo1.maven.org/maven2/org/glassfish/jersey/media/project/2.26/project-2.26.pom
  100.0% [##########] 3.2 KiB (69.5 KiB / s)
https://repo1.maven.org/maven2/org/glassfish/hk2/hk2-parent/2.5.0-b42/hk2-parent-2.5.0-b42.pom
  100.0% [##########] 41.4 KiB (845.5 KiB / s)
[info] Resolved  dependencies
[info] Fetching artifacts of
https://repo1.maven.org/maven2/org/glassfish/hk2/external/javax.inject/2.5.0-b42/javax.inject-2.5.0-b42.jar
  100.0% [##########] 5.8 KiB (52.4 KiB / s)
https://repo1.maven.org/maven2/org/glassfish/jersey/media/jersey-media-jaxb/2.26/jersey-media-jaxb-2.26.jar
  100.0% [##########] 70.2 KiB (444.2 KiB / s)
https://repo1.maven.org/maven2/org/glassfish/jersey/core/jersey-client/2.26/jersey-client-2.26.jar
  100.0% [##########] 177.2 KiB (575.5 KiB / s)
https://repo1.maven.org/maven2/javax/ws/rs/javax.ws.rs-api/2.1/javax.ws.rs-api-2.1.jar
  100.0% [##########] 124.5 KiB (210.0 KiB / s)
https://repo1.maven.org/maven2/org/glassfish/jersey/core/jersey-server/2.26/jersey-server-2.26.jar
  100.0% [##########] 898.6 KiB (946.9 KiB / s)
https://repo1.maven.org/maven2/org/glassfish/jersey/core/jersey-common/2.26/jersey-common-2.26.jar
  100.0% [##########] 1.1 MiB (856.9 KiB / s)
[info] Fetched artifacts of
[success] Total time: 2 s, completed Sep 6, 2019 2:51:52 PM

@howardrotterdam
Copy link

howardrotterdam commented Dec 5, 2019

This is fixed in sbt-1.3.0 unless you've opted out of coursier

But Coursier has random failure problem when used in a corporate intranet with authenticated artifactory server, so we have to stick to Ivy. So I vote on #3618 (comment) to be best simple work around.

@anilkumarmyla
Copy link
Contributor

@howardrotterdam open source software works best when you report bugs/issues to the software in question. Did you file an issue on coursier for the same?

@minnieshi
Copy link

I use sbt 1.3.8, it has the same problem.

@mkharytonau
Copy link

Faced the same issue with sbt 1.3.13, removing sbt-coursier plugin solved this.

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

No branches or pull requests