Jenkins dependencies from sbt dependencies? - jenkins

Is it possible to automatically sync Jenkins build dependencies with sbt dependencies? For example, if project B's build.sbt says that project A (which I also wrote) is a dependency of it, can the Jenkins build for project B be made to automatically detect this fact - and detect any other dependencies that may be added or removed to the build.sbt file in future?

You could use the ScriptTrigger Plugin to write the appropriate code. Or you could write your own plugin and look at IvyTrigger or Maven Dependency Update trigger. That might make a good enhancement to the sbt plugin.

Related

Jenkins Pipeline - Workflow CPS plugin JAR dependencies

I'm implementing unit tests for code used in a Jenkins Pipeline Shared Groovy Library. Specically, I need to mock the steps object available in the Jenkinsfile, which is an instance of org.jenkinsci.plugins.workflow.cps.DSL. In my Gradle build I've specified a dependency like so:
testCompile group: 'org.jenkins-ci.plugins.workflow', name: 'workflow-cps', version: '2.30', ext: 'jar'
which is the project hosting the class above. Without specifying the ext as a JAR, Gradle retrieves the .hpi file since this is the packaging defined in the project's pom.xml; obviously I need to override this and fetch the JAR for my project. However, in doing this Gradle does not download the transitive dependencies of the workflow-cps JAR and I find myself having to populate my build.gradle with all the dependencies determined via trial and error. Is there a way to retrieve the transitive dependencies, or is this a limitation of the workflow-cps project and how it defines its pom.xml?
The CPS class you're wanting to mock won't contain methods/variables introduced by plugins or your workflow lib, so this approach probably won't be fully satisfying.
Facing the same challenge I took the pragmatic approach of making my own TestScript interface in my test sources and Mock that, and not typing the script reference in classes.
The drawbacks are not having IDE code inspection for stuff referencing the script, and having to manually add signatures to TestScript as I add tests (which is also error-prone, since I have manually ensure that those signatures match).
But it works, and avoids getting dragged into plugin dependency hell.

When and how does gradle resolve its dependencies?

I'm trying to re-write our build to Gradle, but we want to keep the dependency management in Ivy, for internal reasons.
So while trying to do that, I'm having several questions regarding the way gradle handles its dependencies:
When does gradle resolve dependencies (without Ivy or anything)?
When adding IvySettings and ivy.xml, do I need to call something similar to ant's ivy:resolve or ivy:configure, or does Gradle take care of that? If so, when and how?
Gradle resolves dependencies (more precisely configurations) on first use (typically by a task). Gradle doesn't read ivysettings or ivy.xml. (It does read ivy.xml files in the repository.) All information about dependency resolution is configured in Gradle build script(s).
In regards to (2), I managed to get gradle to read an ivy.xml file, and resolve the dependencies from there.
Gradle doesn't take care of that naturally, but using code from this issue, with a few tweaks, managed to get dependencies with gradle.
further more, there is a IvyXML plugin for gradle, with claims it can take care of most of this stuff.

How do I make the compile of one maven 3 project depend on the install of another?

I have a directory with a pom.xml and several subdirectories with their own pom.xml files
One subdirectory is local called thirdparty. It contains several jar files and installs them to the local maven repo when a mvn install is executed. These are needed by the mvn compile phase of the other artifacts. The root pom.xml simply executes the same step on each child pom.xml.
I'd like to modify the root pom.xml so that mvn compile will do an install on the third party folder before executing the other folders. I tried this in the maven-compiler-plugin:
<executions>
<execution>
<id>thirdparty</id>
<phase>install</phase>
</execution>
</executions>
I see nothing in the documentation about specifying a phase in a dependency element.
To make sure I have this straight, it sounds like you have an aggregator pom, AGG, and some submodules, A and B, where A is nothing but some third-party jars that have to be installed in the local repo before B will compile. If that's true, then two possibilities spring to mind:
1) Do away with A and instead install the third party jars into an appropriate standalone repo, like a local Nexus server, and add that repo to your pom. That would be the "Maven" way of doing it.
2) Add a dependency on A to B's <dependencies>. In A, configure the install plugin with an execution per jar that needs to be installed, and bind these executions to the compile phase. Then when you run compile on AGG, it will first run compile on A, which will install all the jars, followed by compile on B. Note that this will have the side effect of producing an A.jar, which will be a dependency of B, because maven assumes that every module produces exactly one artifact of some type. You might be forced to add at least one class or resource so that A.jar can actually be built. Not sure about that one. Alternately, you could experiment with setting A's packaging to "pom".
I believe you are using Maven in a wrong way.
Such kind of 3rd party dependencies should be put to local repository (or your internal Maven repository) before you run the compilation work, and dependencies in your project should be setup accordingly. "Installation of 3rd party artifacts" shouldn't be part of the build process.
And, in Maven world, we rarely have 3rd party libs exists as part of the source code. In fact one of the reason for using Maven is to get rid of such kind of libs in source code.
Sounds like you want a couple of dependancies. Look into the depends element.

Include ant libs from within the build file

My problem is the following:
I would like to use the propertyregex task in ant. The project I am working on is built on various different servers and I don't want to configure (install the ant-nodeps.jar) every server. The source needs to include everything, that is not installed on the system by default.
So now I would need to add the ant-nodeps.jar to the ant classpath from within the build file. Does somebody know how to do that?
Cheers,
Robert
The propertyregex task is part of ant-contrib and can be installed as part of your build using Apache ivy
Checkout the following example, which demonstrates how to download and use the "for" task (also from the ant-contrib project):
Problems getting my ANT builds to work after OS upgrade
The one downside is that ivy does not come pre-packaged with ANT, so the following answer has a tip on how to bootstrap your ANT builds. Once ivy is started it can be used to pull down everything else your build needs.
Ivy fails to resolve a dependency, unable to find cause
Update
While I understand you requirement to have no change on the target platforms, it's a very difficult problem to solve if you must also match several old versions of the build software. I have found incompatibilities between the latest ANT and 5 year old versions like 1.7 (ANT 1.6.5 is now 8 years old....)
What I do is install a very limited number of ANT versions on my Jenkins slave nodes. Build jobs can then only choose from these and then use ivy to download all other 3rd party software dependencies (This setup emulates how you'd manage a set of Maven projects).
I suspect you're using ANT to run your deployments? If that is the case I would suggest switching to something like Groovy, which can be deployed as a single jar file and can pull down dependencies on the fly, using Grape.

How to install gradle-grails-plugin?

Complete gradle nooby here.
I want to be able to execute grails build commands like "grails compile", "grails test-app" and so forth from gradle.
I found the grails-gradle-plugin from Peter Ledbrook at: https://github.com/grails/grails-gradle-plugin.
Cloning the repository I get some files and folders. In the readme file it says " include the required JARs via buildscript {} and 'apply' the plugin". The apply part sure I get but how do I add the JAR? And which jar? Do I need to use gradle on the build file in the folder of the downloaded plug-in and compile a jar? And ones I get the jar where do I place it and how do I include it in my projects build.gradle file?
I have a feeling this is going to be ridiculously easy but I just can't get it to work.
In Gradle, the jars are added to build script or to your application class path through dependencies closure e.g.
dependencies {
compile "org.grails:grails-crud:1.3.4"
compile "org.grails:grails-gorm:1.3.4"
compile "ch.qos.logback:logback-core:1.0.7"
compile "org.slf4j:slf4j-api:1.7.2"
}
compile is a name of one of the many configurations (there are also test, runtime etc.) and e.g. "org.grails:grails-crud:1.3.4" is a reference to a jar in one of the public repositories, which are also specified in your scripts in repositories closure.
You can read more about Gradle dependency management in http://gradle.org/docs/current/userguide/dependency_management.html.
For your Grails project you need to define a build.gradle file which looks similar to what is described in the README.
Though I tried today to just create a simple Grails project using that plugin and gradle init command and it didn't work. I have created an issue for that: https://github.com/grails/grails-gradle-plugin/issues/16.

Resources