로컬 Maven 프록시 저장소 (Nexus)를 사용하기 위해 sbt를 얻으려면 어떻게해야합니까?
현재 웹에서 아티팩트를 가져 오는 sbt (Scala) 프로젝트가 있습니다. 아티팩트를 캐시하는 기업 표준 Nexus 저장소로 이동하고 싶습니다. Nexus 문서에서 Maven 프로젝트에 대해 수행하는 방법을 이해합니다. 그러나 sbt는 분명히 다른 접근 방식을 사용합니다. (나는 Ivy가 어떻게 든 관련되어 있다는 것을 이해하지만 그것을 사용한 적이 없으며 어떻게 작동하는지 이해하지 못합니다.)
모든 종속성에 대해 기업 Nexus 저장소 시스템을 사용하도록 sbt 및 / 또는 기본 Ivy에 어떻게 지시합니까? 일종의 프로젝트 수준 구성 파일을 사용하여 소스 저장소의 새 복제본이 자동으로 프록시를 사용하도록 대답하고 싶습니다. (즉, 도트 디렉토리에있는 사용자 별 구성 파일을 사용하는 것은 실행 가능하지 않습니다.)
감사!
1 단계 : 아래에 요약하고 추가 한 Detailed Topics : Proxy Repositories 의 지침을 따릅니다 .
(Artifactory를 사용하는 경우이 단계를 건너 뛸 수 있습니다.) 회사 Maven 저장소에 완전히 별도의 Maven 프록시 저장소 (또는 그룹)를 만들어 다음 두 가지 중요한 저장소와 같은 아이비 스타일 저장소 를 프록시 합니다.
- http://repo.typesafe.com/typesafe/ivy-releases/
- http://repo.scala-sbt.org/scalasbt/sbt-plugin-releases/
일부 저장소 관리자는 함께 혼합되는 Ivy 스타일 및 Maven 스타일 저장소를 처리 할 수 없기 때문에 필요합니다.
다음과 같은 형식으로
repositories
기본 회사 저장소와 1 단계에서 만든 추가 저장소를 모두 나열 하는 파일을 만듭니다 .[repositories] my-maven-proxy-releases: http://repo.example.com/maven-releases/ my-ivy-proxy-releases: http://repo.example.com/ivy-releases/, [organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext]
해당 파일을
.sbt
홈 디렉토리 내의 디렉토리 에 저장 하거나 sbt 명령 줄에서 지정합니다.sbt -Dsbt.repository.config=<path-to-your-repo-file>
이전 버전의 sbt를 사용하는 사람들을위한 좋은 소식 : sbt 0.12.0 런처 jar에서 적어도 이전 sbt 버전의 부팅 속성 파일에는 필수 줄 (을 언급 한 줄)이 포함되어 있지 않지만 repository.config
여전히 작동합니다. 해당 파일을 편집하여 필요한 행을 추가하고 sbt 0.12.0 런처 jar에 다시 패키징하면 해당 버전의 sbt에 대해! 이는 기능이 sbt 자체가 아닌 런처에서 구현되기 때문입니다. 그리고 sbt 0.12.0 런처는 sbt의 모든 버전을 0.7로 바로 시작할 수 있다고 주장합니다!
2 단계 : 외부 리포지토리가 사용되지 않도록하려면 리졸버에서 기본 리포지토리를 제거합니다. 다음 두 가지 방법 중 하나로 수행 할 수 있습니다.
-Dsbt.override.build.repos=true
위의 세부 항목 페이지에 언급 된 명령 줄 옵션을 추가합니다 . 이렇게하면 파일에 지정한 저장소가 sbt 파일에 지정된 저장소를 재정의하게됩니다. 이것은 sbt 0.12 이상에서만 작동 할 수 있지만 아직 시도하지 않았습니다.- 사용
fullResolvers := Seq(
기업 받는다는 저장소에 대한 해결 (들))
대신 빌드 파일,resolvers ++=
또는resolvers :=
또는 당신이 사용하는 데 사용 뭐든간에.
좋습니다. sbt 메일 링리스트에있는 Mark Harrah의 도움을 받아 작동하는 답변이 있습니다.
내 빌드 클래스는 이제 다음과 같습니다 (다른 저장소 포함).
import sbt._
//By extending DefaultWebProject, we get Jetty support
class OurApplication(info: ProjectInfo) extends DefaultWebProject(info) {
// This skips adding the default repositories and only uses the ones you added
// explicitly. --Mark Harrah
override def repositories = Set("OurNexus" at "http://our.nexus.server:9001/nexus/content/groups/public/")
override def ivyRepositories = Seq(Resolver.defaultLocal(None)) ++ repositories
/* Squeryl */
val squeryl = "org.squeryl" % "squeryl_2.8.0.RC3" % "0.9.4beta5"
/* DATE4J */
val date4j = "hirondelle.date4j" % "date4j" % "1.0" from "http://www.date4j.net/date4j.jar"
// etc
}
이제 내 컴퓨터의 .ivy2/cache
디렉토리 에서 Squeryl 트리를 삭제하면 sbt는 적절한 URL을 사용하여 Nexus 트리에서 가져 오려고 합니다. 문제 해결됨!
필요한 것은 다음을 수행 할 수있는 속성 파일을 정의하는 sbt.boot.properties
것입니다.
- 아이비 캐시 위치를 재정의합니다 (그렇지 않으면 매장의 디스크 공간이 심각하게 제한되는 로밍 Windows 프로필 의 일부이기 때문에 필요합니다 . 문제 74 참조 )
- 원하는 다른 Maven 저장소를 정의하십시오.
C : \ HOMEWARE \ apps \ sbt-0.74 \ sbt.boot.properties [스칼라] 버전 : 2.7.7 # 분류 자 : 소스, javadoc [앱] org : org.scala-tools.sbt 이름 : sbt 버전 : read (sbt.version) 클래스 : sbt.xMain 구성 요소 : xsbti 교차 버전 : true 분류 자 : 소스, javadoc [저장소] 현지 my-nexus : http://my.nexus/nexus/content/repositories/scala-tools/, [조직] / [모듈] / [개정] / [유형] s / [아티팩트] (-[분류 자]). [ext] maven-local # sbt-db: http://databinder.net/repo/, [organization]/[module]/[revision]/[type]s/[artifact](-[classifier]).[ext] # maven-central # scala-tools-releases # scala-tools-snapshots [boot] directory: project/boot properties: project/build.properties prompt-create: Project does not exist, create new project? prompt-fill: true quick-option: true [log] level: debug [app-properties] project.name: quick=set(test), new=prompt(Name)[p], fill=prompt(Name) project.organization: new=prompt(Organization)[org.vonc] project.version: quick=set(1.0), new=prompt(Version)[1.0], fill=prompt(Version)[1.0] build.scala.versions: quick=set(2.8.0.RC2), new=prompt(Scala version)[2.8.0.RC2], fill=prompt(Scala version)[2.8.0.RC2] sbt.version : quick = set (0.7.4), new = prompt (sbt 버전) [0.7.4], fill = prompt (sbt 버전) [0.7.4] project.scratch : quick = set (true) project.initialize : quick = set (true), new = set (true) [여자 이름] 캐시 디렉토리 : C : \ HOMEWARE \ projects \ .ivy2 \ cache
참고 :이 sbt.boot.properties
파일은 다음에서 영감을 받았습니다.
- sbt 프로젝트 의 "Generalized Launcher"페이지에 언급 된 것 입니다.
- 그 안에서 발견 된
sbt-0.74
것!
외부 Maven 저장소 정의에 주석을 달고 내 Nexus Maven 저장소에 대한 참조를 추가했습니다.
런처는 우선 순위를 높이기 위해 다음 방법 중 하나로 구성 할 수 있습니다.
- 바꾸기
/sbt/sbt.boot.properties
에서 파일을jar
.sbt.boot.properties
클래스 경로에 이름이 지정된 구성 파일을 넣으십시오 ./sbt
접두사 없이 클래스 경로 루트에 넣으십시오 .- 명령 줄에서 대체 구성의 위치를 지정합니다. 이것은 다음을 통해 수행 할 수 있습니다.
- 위치를 시스템 속성으로 지정하거나
sbt.boot.properties
- 또는 '
@
' 접두사가 붙은 런처의 첫 번째 인수로 .시스템 속성의 우선 순위가 더 낮습니다.
상대 경로의 해상도는 다음과 같습니다.
- 먼저 현재 작업 디렉토리에 대해 시도했습니다.
- 그런 다음 사용자의 홈 디렉토리에 대해
- 그런 다음 실행기 jar를 포함하는 디렉토리에 대해.
이러한 시도가 모두 성공하지 않으면 오류가 생성됩니다.
sbt.bat 래퍼를 정의합니다 (순서대로하면 지정해야합니다 당신을 sbt.boot.properties
같은) :
C:\HOMEWARE>more C:\HOMEWARE\bin\sbt.BAT
@echo off
set t=%~dp0
set adp0=%t:C:\="%"
set SBT_DIR=%adp0%..\apps\sbt-0.74
dir C:\%SBT_DIR%\sbt-launch-0.7.4.jar
# if needed, add your proxy settings
set PROXY_OPTIONS=-Dhttp.proxyHost=my.proxy -Dhttp.proxyPort=80xx -Dhttp.proxyUser=auser -Dhttp.proxyPassword=yyyy
set JAVA_OPTIONS=-XX:+CMSClassUnloadingEnabled -XX:MaxPermSize=256m -Xmx512M -cp C:\HOMEWARE\apps\sbt-0.74\sbt-launch-0.7.4
set SBT_BOOT_PROPERTIES=-Dsbt.boot.properties="sbt.boot.properties"
cmd /C C:\HOMEWARE\apps\jdk4eclipse\bin\java.exe %PROXY_OPTIONS% %JAVA_OPTIONS% %SBT_BOOT_PROPERTIES% -jar C:\HOMEWARE\apps\sbt-0.74\sbt-launch-0.7.4.jar %*
And your sbt will download artifacts only from:
- your Nexus
- your local Maven repo.
Just tested at home with an old Nexus opensource 1.6 I had running, java 1.6, sbt07.4
C:\Prog\Java\jdk1.6.0_18\jre\bin\java -Xmx512M -Dsbt.boot.properties=sbt.boot.properties - jar "c:\Prog\Scala\sbt\sbt-launch-0.7.4.jar"
That gives:
[success] Build completed successfully.
C:\Prog\Scala\tests\pp>sbt
Getting Scala 2.8.0 ...
downloading http://localhost:8081/nexus/content/repositories/scala/org/scala-lang/scala-compiler/2.8.0/scala-compiler-2.
8.0.jar ...
[SUCCESSFUL ] org.scala-lang#scala-compiler;2.8.0!scala-compiler.jar (311ms)
downloading http://localhost:8081/nexus/content/repositories/scala/org/scala-lang/scala-library/2.8.0/scala-library-2.8.
0.jar ...
[SUCCESSFUL ] org.scala-lang#scala-library;2.8.0!scala-library.jar (185ms)
:: retrieving :: org.scala-tools.sbt#boot-scala
confs: [default]
2 artifacts copied, 0 already retrieved (14484kB/167ms)
[info] Building project test 0.1 against Scala 2.8.0
[info] using sbt.DefaultProject with sbt 0.7.4 and Scala 2.7.7
If I try a funny value in the sbt.boot.properties file:
C:\Prog\Scala\tests\pp>sbt
Getting Scala 2.9.7 ...
:: problems summary ::
:::: WARNINGS
module not found: org.scala-lang#scala-compiler;2.9.7
==== nexus: tried
http://localhost:8081/nexus/content/repositories/scala/org/scala-lang/scala-compiler/2.9.7/scala-compiler-2.9.7.pom
-- artifact org.scala-lang#scala-compiler;2.9.7!scala-compiler.jar:
http://localhost:8081/nexus/content/repositories/scala/org/scala-lang/scala-compiler/2.9.7/scala-compiler-2.9.7.jar
So it does limit itself to the two repo I defined:
[repositories]
nexus: http://localhost:8081/nexus/content/repositories/scala
nexus2: http://localhost:8081/nexus/content/repositories/scala, [organization]/[module]/[revision]/[type]s/[artifact](-[classifier]).[ext]
(I commented everything else: local
, maven-local
, ...)
If I comment all repositories and put a funny value (2.7.9) for the scala version in the sbt.boot.properties
, I do get (like the OP did)
C:\Prog\Scala\tests\pp>sbt
Error during sbt execution: No repositories defined.
If I put 2.7.7 (while still having all repo commented), yes, it won't generate an error:
C:\Prog\Scala\tests\pp>sbt
[info] Building project test 0.1 against Scala 2.8.0
[info] using sbt.DefaultProject with sbt 0.7.4 and Scala 2.7.7
But that's only because it already had downloaded scala2.8.0 during my previous tries.
If I remove that library from my project/boot
directory, then it will throw an Exception:
[info] using sbt.DefaultProject with sbt 0.7.4 and Scala 2.7.7
> C:\Prog\Scala\tests\pp>sbt
Error during sbt execution: No repositories defined.
at xsbt.boot.Pre$.error(Pre.scala:18)
at xsbt.boot.Update.addResolvers(Update.scala:197)
...
at xsbt.boot.Boot$.main(Boot.scala:15)
at xsbt.boot.Boot.main(Boot.scala)
Error loading project: Error during sbt execution: No repositories defined.
edit the config file in sbt_home/conf "sbtconfig.txt"
add two line
-Dsbt.override.build.repos=true
-Dsbt.repository.config="C:/Program Files (x86)/sbt/conf/repo.properties"
the repo.properties content is
[repositories]
local
public: http://222.vvfox.com/public <-fix this ,write your local nexus group url
Well this has bugged me for a while so I found a guy that has written an SBT plugin for maven out on github called maven-sbt so all you have to do is include it in your plugins project and make your project mixin with maven.MavenDependencies and all your operations like update and publish-local work with your local maven. The nice thing about that is if you are like me, your org is all maven. So, all you libs are in you local maven repo but if for some reason you build with sbt first, then you start getting a bunch or jars in ivy too. What a waste of space, and time since you will still need to get them for your maven builds.
That said, I wish this were built into sbt so I would not need to add it to every project. Maybe as a processor at least. He mentioned in one thing I read that he would like to add it to 0.9 but I have not been able to find it.
I got this error because I had a blank file in ~/.sbt/repositories
. Both adding repositories to the file and removing the file solved the problem.
'Development Tip' 카테고리의 다른 글
SQL Server 데이터베이스에서 UTF-8 데이터 정렬을 사용하는 방법은 무엇입니까? (0) | 2020.10.27 |
---|---|
가져올 진행률 표시기를 업로드 하시겠습니까? (0) | 2020.10.27 |
HttpRequest를 HttpRequestBase 개체로 어떻게 변환합니까? (0) | 2020.10.26 |
git 별칭을 어떻게 삭제할 수 있습니까? (0) | 2020.10.26 |
Visual Studio 용 Xamarin을 사용하여 실제 Android 디바이스에서 디버그하려면 어떻게하나요? (0) | 2020.10.26 |