gpt4 book ai didi

scala - 没有代码更改的 Scala Maven 重新编译错误

转载 作者:行者123 更新时间:2023-12-02 02:17:09 27 4
gpt4 key购买 nike

当我结帐时 https://github.com/alexeyr/scala-time并使用 Maven 构建一次,一切正常。然后我触摸 src/main/scala/org/scala_tools/time/Implicits.scala 以触发重新编译。再次运行 mvn compile,我得到类似于

的 56 个错误
[ERROR] F:\MyProgramming\scala-time\src\main\scala\org\scala_tools\time\StaticDateTime.scala:29: error: value second is not a member of Int
[ERROR] def nextSecond = now + 1.second

它似乎没有看到被触摸的文件中定义的隐式,并用 import org.scala_tools.time.Implicits._ 导入。但同时没有错误 object Implicits is not a member of package org.scala_tools.time,正如我希望在这种情况下看到的那样。

mvn clean后可以再次编译一次没有报错。

  1. 任何人都可以复制这个吗?

  2. 如果是,我该如何解决?

更新:SBT 也会发生这种情况,但前提是 Implicits.scala 实际更改足以生成不同的类文件(例如添加一行 object Implicits2 extends Implicits) .而且错误集是不同的!

最佳答案

我可以在没有 maven 的情况下重新创建错误,所以看起来这可能是 scalac 的使用方式的问题(或者 scalac< 的错误):

% rm -rf target
% mkdir -p target/classes
% cat scalac-args | sed "s;~;$HOME;g" | xargs scalac-2.9 # runs successfully
% cat scalac-args | sed "s;~;$HOME;g" | xargs scalac-2.9
#...
56 errors found

(sed 命令只是解析 scalac-args 中的 .m2 目录)

scalac-args 在哪里

-target:jvm-1.5
-classpath
~/.m2/repository/org/scala-lang/scala-library/2.9.1-1/scala-library-2.9.1-1.jar:~/.m2/repository/org/joda/joda-convert/1.2/joda-convert-1.2.jar:~/.m2/repository/joda-time/joda-time/2.1/joda-time-2.1.jar:target/classes
-d
target/classes
src/main/scala/org/scala_tools/time/DurationBuilder.scala
src/main/scala/org/scala_tools/time/Implicits.scala
src/main/scala/org/scala_tools/time/Imports.scala
src/main/scala/org/scala_tools/time/RichAbstractDateTime.scala
src/main/scala/org/scala_tools/time/RichAbstractInstant.scala
src/main/scala/org/scala_tools/time/RichAbstractPartial.scala
src/main/scala/org/scala_tools/time/RichAbstractReadableInstantFieldProperty.scala
src/main/scala/org/scala_tools/time/RichChronology.scala
src/main/scala/org/scala_tools/time/RichDate.scala
src/main/scala/org/scala_tools/time/RichDateMidnight.scala
src/main/scala/org/scala_tools/time/RichDateTime.scala
src/main/scala/org/scala_tools/time/RichDateTimeFormatter.scala
src/main/scala/org/scala_tools/time/RichDateTimeProperty.scala
src/main/scala/org/scala_tools/time/RichDateTimeZone.scala
src/main/scala/org/scala_tools/time/RichDuration.scala
src/main/scala/org/scala_tools/time/RichInstant.scala
src/main/scala/org/scala_tools/time/RichInt.scala
src/main/scala/org/scala_tools/time/RichLocalDate.scala
src/main/scala/org/scala_tools/time/RichLocalDateProperty.scala
src/main/scala/org/scala_tools/time/RichLocalDateTime.scala
src/main/scala/org/scala_tools/time/RichLocalDateTimeProperty.scala
src/main/scala/org/scala_tools/time/RichLocalTime.scala
src/main/scala/org/scala_tools/time/RichLocalTimeProperty.scala
src/main/scala/org/scala_tools/time/RichLong.scala
src/main/scala/org/scala_tools/time/RichMonthDay.scala
src/main/scala/org/scala_tools/time/RichMonthDayProperty.scala
src/main/scala/org/scala_tools/time/RichPartial.scala
src/main/scala/org/scala_tools/time/RichPartialProperty.scala
src/main/scala/org/scala_tools/time/RichPeriod.scala
src/main/scala/org/scala_tools/time/RichReadableDateTime.scala
src/main/scala/org/scala_tools/time/RichReadableDuration.scala
src/main/scala/org/scala_tools/time/RichReadableInstant.scala
src/main/scala/org/scala_tools/time/RichReadableInterval.scala
src/main/scala/org/scala_tools/time/RichReadablePartial.scala
src/main/scala/org/scala_tools/time/RichReadablePeriod.scala
src/main/scala/org/scala_tools/time/RichYearMonth.scala
src/main/scala/org/scala_tools/time/RichYearMonthProperty.scala
src/main/scala/org/scala_tools/time/StaticDateTime.scala
src/main/scala/org/scala_tools/time/StaticDateTimeFormat.scala
src/main/scala/org/scala_tools/time/StaticDateTimeZone.scala
src/main/scala/org/scala_tools/time/StaticDuration.scala
src/main/scala/org/scala_tools/time/StaticInterval.scala
src/main/scala/org/scala_tools/time/StaticLocalDate.scala
src/main/scala/org/scala_tools/time/StaticLocalDateTime.scala
src/main/scala/org/scala_tools/time/StaticLocalTime.scala
src/main/scala/org/scala_tools/time/StaticPartial.scala
src/main/scala/org/scala_tools/time/StaticPeriod.scala

并且已经下载了合适的 jar。

如果我在 -classpath 参数中将 target/classes 替换为 target/classes/org/scala_tools/time/,那么它就可以工作那就好。

% rm -rf target
% mkdir -p target/classes
% cat scalac-args | sed "s;~;$HOME;g" | xargs scalac-2.9 # runs successfully
% cat scalac-args | sed "s;~;$HOME;g" | xargs scalac-2.9 # runs successfully

所以看起来 maven-scala-plugin 期望 scalac 在给定路径上的目录时查找包适当的子目录,但是 scalac 没有这样做。我不确定谁错了。

关于scala - 没有代码更改的 Scala Maven 重新编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9959199/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com