SBT dependency on non-SBT library - maven

My Play/SBT project needs to depend on a third-party Java library that is distributed in source form and can be built with either Ant or Maven. Its root directory contains pom.xml and build.xml.
I am thinking of having this library added as a git submodule and have SBT build it as a subproject. I tried adding
externalPom(baseDirectory(_ / "pathToLibrary" / "pom.xml"))
to my build settings, but I ended up with the following compiler error:
[info] Compiling 32 Scala sources and 5 Java sources to /home/thesamet/project]
[error] (compile:compile) scala.reflect.internal.MissingRequirementError: object scala.runtime in compiler mirror not found.
[error] Total time: 1 s, completed Aug 23, 2013 11:46:20 AM

An external pom can only be used to obtain library dependencies of the maven project but not compile it.
You can add an sbt build configuration for the external project or easier, you can publish the third-party module to a corporate Maven or Ivy repository or just local with mvn install and add ~/.m2 as file resolver to your SBT project.

Related

How to recompile gradle dependency from sources?

We have a dependency dep which was originally compiled in Java 8. The project requiring this dependency is compiled and run with Java 6. This results ``bad major version'' error.
We have the sources available in our central repository for dep and looking for a way that the sources are downloaded in build.gradle:
compile('dep_group:dep_artifact:version:sources')
and then recompile in JDK 6 to produce the required jar file.
Is it possible? Or any suggestions?
Alternatively, we have to download the code of dep offline, recompile with JDK 6, publish the jar file and finally add it as a dependency. But we are looking to avoid this long route. This is just for testing purposes and we do not want to publish a new version compiled with an older version of Java.
Without original build file (POM / build.gradle / ant.xml) you cannot recompile library. If it is a rather simple library - possible option is to include its sources as additional module in multi-module Gradle project:
Download sources
Create folder for them in your project
Create additional module as described in Gradle docs: https://docs.gradle.org/current/userguide/multi_project_builds.html
Apply java plugin for module
Set dependency on this project in format: compile(project(':dep'))
Finally, when you build your project Gradle will compile this module and use it as dependency for your main module.
Do not forget to check library license, e.g. Apache License 2 permits such a simple usage of sources.

Building an Eclipse plugin using Maven

I am trying to configure Maven to build an Eclipse application (Eclipse plugin packaged with all of the Eclipse EXEs etc).
I have already Mavenised dozens of dependencies of the project and deployed them to our internal Nexus (OSS) server. I have also installed the Nexus P2 Repository Plugin and the P2 Bridge Plugin (2.6.3-01) and the Nexus Unzip Plugin (0.12.0). I can browse to the .meta/p2 folder of our group repository, but it is currently empty.
This should be a lot simpler than it currently appears to be. I'm targeting Eclipse 3.4.2 (Ganymede) on Windows. If it makes any difference, we actually deploy our application packaged as a stripped-down/customised Eclipse installation.
eclipse-repository
When I run maven against a pom with <packaging>eclipse-repository</packaging> I get the following error:
[ERROR] Missing requirement: MyApp 0.0.0 requires
'org.eclipse.equinox.executable.feature.group 0.0.0'
but it could not be found
...where do I get that from, and how do I add it to Nexus?
When I run maven against a pom with <packaging>eclipse-plugin</packaging> I get the following error:
[ERROR] Missing requirement: MyApp 0.0.0 requires
'bundle org.eclipse.ui 0.0.0'
but it could not be found
...but I found the following directories on my local file system (suspect itp-04-rcp generated the first one):
D:\maven\repository\p2\osgi\bundle\org.eclipse.ui\3.6.2.M20110203-1100
D:\maven\repository\p2\osgi\bundle\org.eclipse.ui\3.7.0.v20110928-1505
Tycho POM-First artifacts
I've also tried the pom-first-dependencies and manifest-first-dependency combo: http://wiki.eclipse.org/Tycho/How_Tos/Dependency_on_pom-first_artifacts
I don't understand how this works - I can build itp02 from Git. I can see that it builds two bundles:
+---------------------+---------------------+--------------------------------------+
| artifactId | Bundle-Name | Bundle-SymbolicName |
+---------------------+---------------------+--------------------------------------+
| pomfirst-bundle | pomfirst-bundle | tycho.demo.itp02.pomfirst-bundle |
| pomfirst-thirdparty | pomfirst-thirdparty | tycho.demo.itp02.pomfirst-thirdparty |
+---------------------+---------------------+--------------------------------------+
...but how does build02 pick these up? The only bit that seems relevant is:
Import-Package: tycho.demo.itp02.pomfirst
...that doesn't have anything to do with either of the Bundle-Names.
Felix Maven Bundle Plugin
I tried the Felix maven-bundle-plugin. I include all of my regular maven dependencies in a pom with <packaging>bundle</packaging>.
mvn deploy creates something at /nexus/content/repositories/snapshots/.meta/p2/plugins. I can download the jar via a browser, but all of the dependency jars are named "artifact-vresion" rather than "artifact_version" - is that right?
mvn bundle:bundleall creates an OSGI bundle for each of the transitive dependencies, but I'm not sure what to do with them from here.
mvn bundle:deploy refuses to do anything unless I specify -DremoteOBR and probably a few other parameters which I don't really understand.
The 'org.eclipse.equinox.executable.feature.groug' seems to be necessary if you build an eclipse product which includes the native launchers ("include laucher" property set to true in product configuration). Try to add the feature to your platform definition (e.g. copy from eclipse p2 repo or your running eclipse IDE).
See also https://bugs.eclipse.org/bugs/show_bug.cgi?id=407272
Regards,
Paolo
To solve the Problem concerning the missing dependencies:
[ERROR] Missing requirement: MyApp 0.0.0 requires
'bundle org.eclipse.ui 0.0.0'
but it could not be found
seems that your Feature/Plugin MyApp requires to download the org.eclipse.ui Plug-in before it can be installed.
You should check your settings from your configuration-pom like this:
<properties>
<tycho.version>0.25.0</tycho.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<repository.url>http://download.eclipse.org/releases/neon</repository.url>
</properties>
<repositories>
<repository>
<id>NeonRepository</id>
<url>${repository.url}</url>
<layout>p2</layout>
</repository>
if you have set up your self-hosted p2 repository, make sure that the page is correctly build.
You can check this if you select(in eclipse) Help -> Install New Software.
Eclipse should show the provided parts.
If nothing is shown, even if you have deselected every checkbox, you should check your p2-repository.
It should contain the "features" and "plugins" container as well as the artifacts.jar and content.jar.
If you have only the two folders, you should run
eclipse -application org.eclipse.equinox.p2.publisher.UpdateSitePublisher
-metadataRepository file:/<some location>/repository
-artifactRepository file:/<some location>/repository
-source /<location with a site.xml>
-configs gtk.linux.x86
-compress
-publishArtifacts
in a CLI/Shell.
For more Information check the eclipse documentation.
Can you make maven/tycho instantiate a target platform against which you can build your source plugins? http://www.vogella.com/articles/EclipseTycho/article.html

tycho plugin + maven-dependency-plugin: copy dependencies from local projects instead repositories

Main Goal: deploy a project as jar and eclipse-plugin
current state: project builds fine as jar package
Now i want to create a second project which wraps the jar project as eclipse plugin
use tycho-maven-plugin to create eclipse-plugin
add the jar of the original project (with copy-dependency)
add an Activator
export packages from jar
create correct MANIFEST.MF
i tried to copy the jar with copy-dependencies bound to create-resources. This works as long the jar is found in repository, but the local project gets ignored.
This results in a build failure since the jar is not found.
Is it possible to tell copy-dependencies to take the jar from the target directory of the project? Or should i use some other method than using tycho?
Edit:
I solved my problem with 4 projects:
normal project (nothing special here)
the wrapper project using tycho maven and copy-dependencies.
bound copy dependencies to some goal before compile (e.g. generate-resources). Excluded all artefactid which were set as dependency in the MANIFEST.MF.
a prepare project, which calls the normal project and installs it into the repo. This is needed because the tycho-maven-plugin is bound to validate and it is not possible to call the exec plugin beforehand (at least not easy).
a multi module project which calls the prepare project before the wrapper project.
Build your local project (which artifact was missed) with "mvm install". It will be deployed in your local repository ($USER_HOME$/.m2/repositories). After this dependency should be resolved.
Alternatively you can "mvn deploy" if you have local company maven repository like Artifactory or Nexus.

Why is sbt missing dependency on Vaadin project

I've created a Vaadin project using maven, and installed the war in my local maven repository.
This project defines a public class, com.whatever.User.
Then, I created an sbt project wherein I'd like to add a depenecy on the Vaadin project - in order to test it's logic. In the build.sbt file of my sbt project I've added:
resolvers += "Local Maven Repository" at "file://"+Path.userHome+"/.m2/repository"
libraryDependencies ++= Seq(
"com.whatever" % "something" % "1.0"
)
After reloading the sbt project I tried using the User object from inside the sbt project. But I'm getting this error:
> test
[info] Compiling 1 Scala source to /Users/me/projects/something-test/target/scala-2.9.1/classes...
[error] /Users/me/projects/something-test/src/main/scala/TryingUser.scala:1: object whatever is not a member of package com
[error] import com.whatever.User
[error] ^
[error] one error found
[error] {file:/Users/me/projects/something-test/}default-1bc94a/compile:compile: Compilation failed
[error] Total time: 3 s, completed 2012-apr-25 13:44:56
what am I missing? Why isn't sbt adding this dependency?
I can't see sbt, or indeed any other build tool, being able to use war files as dependencies. Think about what the classpath passed to javac or java would look like. The compiler will presumably just see it as a standard zip file and won't be aware that the actual classes are in WEB-INF/classes.
I think you'd need to package the classes as a jar file and use that as a dependency.

maven attach dependencies

I create a simple maven 109 project - maven-archetype-quickstart. Then, add to pom.xml a dependency to derby.
When I run mvn dependency:tree, I see, that the dependency parsed correctly: [INFO] \- org.apache.derby:derby:jar:10.8.1.2:compile. But when I see the package generated by mvn package, it has only 3.2kB and the dependency is not there. Why? How it works?
Because most people don't want all dependencies in their JAR by default. Imagine the people who want to use your artifact but a different version of derby.
To create an "ueber JAR" (i.e. a JAR which contains everything necessary to run it), use the Maven assembly plugin (search for "Creating an Executable JAR").

Resources