Publish a jar file to GitLab package repository - scala

I have a scala project, and using SBT I was able to generate a jar file out of it.
My next challenge is to to publish the generated jar file into Gitlab's package repository so I can reference this jar file (module) in another scala project.
I found several resources for that, using MAVEN or SBT .. but not sure how do I start, because I'm new to it and I'm a bit lost. Is it possible to publish the file using SBT as well?
Reference 1: I'm lost in between GRADLE and MAVEN
Reference 2: I'm lost with this, because It's not clear to me how to achieve it and what is the relation in between the maven repository and the jar file.
Any simple guidance/clarification is greatly appreciated.

You should look at the SBT way of publishing: https://www.scala-sbt.org/1.x/docs/Publishing.html
And then adapt the "repository URL" to be the one of your Gitlab. And follow Gitlab documentation of any specific configuration must be defined.

Related

Download compile and publish from within SBT Task

I have a dependency on a project that is not published online, i need to download the Zip from github, compile it and publish local. So my dependency can be resolved.
Is there a way to do that with sbt. This code shows how to do the download part download a zip from url and extract it in resource using SBT but not the compile and publish part
Can anyone help or give pointer please.
If your purpose is only to depend on a project on github you don't need to go through all of that, you can simply directly depend on that project as in this:
https://stackoverflow.com/a/7550450/913053

SBT: How to publish both the aggregate project and all modules on Sonatype?

I have a SBT project which I was publishing to Sonatype with no issue and I converted it to a multi-module SBT project. Now I want to:
publish the jar/javadoc/sources/pom file containing all the aggregated submodules to Sonatype
(meaning that they should be signed with the sbt-pgp plugin)
publish each individual submodule to Sonatype as well
I tried to use the sbt assembly plugin for this but didn't manage to get very far. Do you have a sample Build.scala file which would show what is the best structure to accomplish this?
I don't know if it's possible with currently available plugins, but using ScopeFilter, you might be able to create an artificial project that aggregates all sources, from there it's just the matter of calling publishSigned in there.
See how I aggregate source in sbt-unidoc.
Here's the proof of concept: https://github.com/eed3si9n/specs2/commit/18f6405c91cf995f621a84c65e05d66407ba4964
With the change I was able to run package, doc etc. You might have to aggregate *.class if you use macros.
I use the sbt assembly plugin for Casbah - https://github.com/mongodb/casbah
Casbah has a top level aggregate project but I also package a single all dependencies jar by adding an extra artifact to the build:
addArtifact(Artifact("casbah-alldep", "pom", "jar"), assembly),
See the build file for more info: https://github.com/mongodb/casbah/blob/master/project/CasbahBuild.scala

Using a library from github not existing in mvn repository

There is a Scala library for redis https://github.com/debasishg/scala-redis. It doesn't exist in mvnrepository.com. It's even not written at github how I must use it (add it as a dependency).
So how do I do that, how do I do add it as a dependency in my project?
If you look at the scala-redis' SBT Project file, it's recorded as redisclient. Searching for the same in maven sonatype, I get this result. Assuming you're using scala-2.10 - if not, you can see the list of released builds for other versions here.

scala sbt cache x eclipse build path

I'm added a dependence to my build.sbt (casbah). I did a sbt update, I did check my ~/.ivy2/cache directory and all jars are there. Do I have to add this ~/.ivy/cache directory to my Build Path and add the casbah as external Jar to my project? If no, probably no because I did try it, what should I do to be able to use this jar in my scala project?
EDIT
I found this instructions that helped me, but still a hack
Establish a simple project (general/project) named "IvyCache"
located at your ".ivy2/cache" folder just for library reference
purposes.
Establish a Scala project located at your "project" folder.
Add the following libraries to the Scala project by means of "Add
JARs" to the "Java Build Path":
3.a) All jars from "/IvyCashe/org.scala-tools.sbt" filterred by
"*2.9.1-0.11.2" or any other Scala/SBT version numbers.
3.b) A single sbinary_*.jar from "/IvyCache/org.scala-tools.sbinary".
3.c) A single test-interface*.jar from "/IvyCache/org.scala-
tools.testing".
Now your build files should compile within Eclipse.
The easiest way to manage this is to use the eclipse plugin for sbt. Then you can just say sbt eclipse on the command line any time you change the dependencies in build.sbt, and the Eclipse files will be automatically updated for you.
Doing it this way means that you will never have to manually configure your Eclipse build path. After all, sbt already knows how to construct the build path, so there's no reason you would have to do it manually.

Get a Hudson build with Maven

I have moved to Maven recently, and since it works fine for resources up to date in some repositories, it's not obvious for non-maven ones.
I have something very simple to achieve (in the idea), but that I am unable to express so far:
I need to compile my code with a jar that can be found here:
https://hudson.eclipse.org/hudson/view/WTP/job/cbi-wtp-wst.xsl.psychopath/ws/sourceediting/plugins/org.eclipse.wst.xml.xpath2.processor/target/
What do I have to put in my pom.xml to make Maven downloading the .jar + the java source + the javadoc, and eventually the other dependencies (actually IBM ICU, Xerces, JavaCup) that are mentionned in the supplied MANIFEST ?
I have read lots of documents, including those with a plugin called Tycho, but nothing helpfull for that simple task.
Thanks for your help.
Maven only works well if all artifacts needed for a build are contained in the local or a configured remote repository. So you have to do the following jobs:
Find out if eclipse plugins are deployed in a Maven2-style repository, and what the URL of that repository is.
Then find out which version of that plugin (artifact) you need.
Maven allows you to configure what will be copied locally: jar file, sources and api doc if you want to.
Maven should then be responsible to download as well all needed artifacts for the plugin you want to use.
After looking at the contents of the URL you gave us (especially the file p2content.xml), it looks like there should be a repository. I searched for the maven repository for org.eclipse.wst.xml.xpath2 and found the URL http://maven.eclipse.org/nexus/content/repositories/testing/org/eclipse/wst/org.eclipse.wst.xml.xpath2/1.1.0/org.eclipse.wst.xml.xpath2-1.1.0.pom
So the repository you are searching for is located at http://maven.eclipse.org/nexus. Just open it, search for example for xpath2, and Nexus, the repository software used there will you show the available artifacts. Depending on what was deployed to that repository, it may contain only the library, or have even sources and JavaDoc bundled with it. For the example above (xpath2), there seems to be only the POM itself and the library (the jar). If you take as example junit, you will find all versions and variants, even with sources.jar and javadoc.jar.
After you have found the needed artifact, you can include it in the dependency section of your POM. And you have to add http://maven.eclipse.org/nexus as a remote repository in the configuration of your Maven installation.
The question and its answer Get source JARs from Maven repository explain how to fetch sources and JavaDoc (if they are available).
You need a maven repository which contains this artifacts (i don't know, if Eclipse hosts a repository for their projects). You can also deploy manually the artifacts to a local repository on your computer.