【发布时间】:2020-08-19 07:57:47
【问题描述】:
我有一个用 Scala 编写的 Spring Boot 应用程序。我正在使用 SBT 来构建项目。我已经使用“sbt-assembly”生成了一个大的胖 jar,并将所有必需的依赖项添加为一个。
sbt.version = 1.3.5 scalaVersion := "2.13.1"
下面是我的 build.sbt 文件
import BuildUtils.readVersion
name := "DiscoveryEngine"
version := "0.1"
scalaVersion := "2.13.1"
organization := "com.javasree.scala.discoveryengine"
publishMavenStyle := true
lazy val artifactoryRepo = settingKey[sbt.librarymanagement.Resolver]("Artifactory repository value")
isSnapshot := {
sys.props.getOrElse("DISCOVERY_ENGINE_SNAPSHOT", sys.env.getOrElse("DISCOVERY_ENGINE_SNAPSHOT", "true")) match {
case "true" | "1" => true
case "false" | "0" => false
case _ => println("taking the default value as true for 'SNAPSHOT'")
true
}
}
publishArtifact in (Compile, packageDoc) := false
publishArtifact in (Compile, packageSrc) := false
/*
if env variable(DISCOVERY_ENGINE_SNAPSHOT) is set to true then build will do "snapshot"
or else it will be "release"
* */
version := {
readVersion("app-build")+
(isSnapshot.value match {
case true => "-SNAPSHOT"
case false => ""
})
}
artifactoryRepo := {
val repoURL = "http://localhost:8081/artifactory"
(isSnapshot.value match {
case true => "jfrog-snapshot" at s"${repoURL}/javasree-sbt-snapshot;build.timestamp=" + new java.util.Date().getTime
case false => "jfrog-remote" at s"${repoURL}/javasree-sbt-local"
})
}
publishTo := Some( artifactoryRepo.value )
credentials += Credentials("Artifactory Realm", "localhost", "admin", "password")
assemblyMergeStrategy in assembly := {
case PathList("META-INF", xs @ _*) => MergeStrategy.discard
case x => MergeStrategy.last
}
libraryDependencies ++= Seq(
"com.google.code.gson" % "gson" % "2.8.2" % "provided"
)++Dependencies.springDependencies
我是 scala 和 sbt 的新手。由于谷歌搜索,一些东西是盲目添加的。只是为了确保我的构建工作。一种这样的代码是程序集合并策略。
当我遇到“重复数据删除发现错误”时,我使用了不同的 mergeStrategy 代码。经过几次跟踪和错误方法后,我终于能够生成胖罐子了。最初我的胖罐子没有成功运行,因为它再次失败并出现不同的错误“无法加载主......”。 上面的构建脚本是我生成胖 jar 的最终脚本,我能够运行 jar。这次它没有给出“无法加载主...”错误,而是给了我新的不同错误,如下所示。
$ java -jar DiscoveryEngine-assembly-1.0-SNAPSHOT.jar
00:44:54.232 [main] DEBUG org.springframework.web.context.support.StandardServletEnvironment - Activating profiles []
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.0-SNAPSHOT)
00:44:54.323 [main] INFO scala.App - Starting App v1.0-SNAPSHOT on LAPTOP-U3JTGOFA with PID 5648 (H:\Projects\Scala\DiscoryEngine\target\scala-2.13\DiscoveryEngine-assembly-1.0-SNAPSHOT.jar started by sree in H:\Projects\Scala\DiscoryEngine\target\scala-2.13)
00:44:54.324 [main] DEBUG scala.App - Running with Spring Boot v1.0-SNAPSHOT, Spring v1.0-SNAPSHOT
00:44:54.324 [main] INFO scala.App - No active profile set, falling back to default profiles: default
00:44:54.325 [main] DEBUG org.springframework.boot.SpringApplication - Loading source class com.javasree.scala.discoveryengine.DiscoveryEngine
00:44:54.367 [main] DEBUG org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext - Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@1445d7f
00:44:54.378 [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating shared instance of singleton bean 'org.springframework.context.annotation.internalConfigurationAnnotationProcessor'
00:44:54.477 [main] ERROR org.springframework.boot.SpringApplication - Application run failed
java.lang.IllegalArgumentException: No auto configuration classes found in META-INF/spring.factories. If you are using a custom packaging, make sure that file is correct.
at org.springframework.util.Assert.notEmpty(Assert.java:464)
at org.springframework.boot.autoconfigure.AutoConfigurationImportSelector.getCandidateConfigurations(AutoConfigurationImportSelector.java:173)
at org.springframework.boot.autoconfigure.AutoConfigurationImportSelector.getAutoConfigurationEntry(AutoConfigurationImportSelector.java:116)
at org.springframework.boot.autoconfigure.AutoConfigurationImportSelector$AutoConfigurationGroup.process(AutoConfigurationImportSelector.java:396)
at org.springframework.context.annotation.ConfigurationClassParser$DeferredImportSelectorGrouping.getImports(ConfigurationClassParser.java:875)
at org.springframework.context.annotation.ConfigurationClassParser$DeferredImportSelectorGroupingHandler.processGroupImports(ConfigurationClassParser.java:801)
at org.springframework.context.annotation.ConfigurationClassParser$DeferredImportSelectorHandler.process(ConfigurationClassParser.java:771)
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:185)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:315)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:232)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:275)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:95)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:705)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:531)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:743)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:390)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:312)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1214)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1203)
at com.javasree.scala.discoveryengine.DiscoveryEngine$.delayedEndpoint$com$javasree$scala$discoveryengine$DiscoveryEngine$1(DiscoveryEngine.scala:13)
at com.javasree.scala.discoveryengine.DiscoveryEngine$delayedInit$body.apply(DiscoveryEngine.scala:12)
at scala.Function0.apply$mcV$sp(Function0.scala:39)
at scala.Function0.apply$mcV$sp$(Function0.scala:39)
at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:17)
at scala.App.$anonfun$main$1(App.scala:73)
at scala.App.$anonfun$main$1$adapted(App.scala:73)
at scala.collection.IterableOnceOps.foreach(IterableOnce.scala:553)
at scala.collection.IterableOnceOps.foreach$(IterableOnce.scala:551)
at scala.collection.AbstractIterable.foreach(Iterable.scala:921)
at scala.App.main(App.scala:73)
at scala.App.main$(App.scala:71)
at com.javasree.scala.discoveryengine.DiscoveryEngine$.main(DiscoveryEngine.scala:12)
at com.javasree.scala.discoveryengine.DiscoveryEngine.main(DiscoveryEngine.scala)
00:44:54.479 [main] DEBUG org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext - Closing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@1445d7f, started on Tue May 05 00:44:54 IST 2020
我确信这与我的 sbt-assembly 插件和我的 MergeStrategy 有关,但 SO 的另一个线程中的解决方案没有解决我的问题,除了询问 SO 专家之外,我别无选择并交叉我的手指以获得正确的答案。先感谢您。
【问题讨论】:
-
这里是我在 GitHub github.com/ghostrider1255/discoveryengine 中的完整代码的链接。
标签: java scala spring-boot sbt sbt-assembly