Merging independent modules in Uber JAR - maven-3

I have independent modules (Spring Boot Application with imbedded Tomcat) in a multimodule project. Have requirement to merge artifact of all modules in one JAR. By passing parameters of specific module, I should able to run the jar which should load that module.
e.g -
I have module A, B and C with all the properties file associated to individual module.
Module A, src/main/resources/application-A-.properties
Module B, src/main/resources/application-B-.properties, -
Module C, src/main/resources/application-C-.properties
Creating a new module D which dependent on A, B and C as
Module D with resources as below,
config/A/application-A-.properties
config/B/application-B-.properties
config/C/application-C-.properties
Once we create a Fat JAR or Uber JAR (say, D-shade-test.jar) then I should be able to run the application by calling jar with parameter, like
java -jar D-shade-test.jar --spring.config.location=classpath:/config/A/application-A-.properties
Thanks in advance.

Related

Combining multiple jenkins shared libraries

Is it possible to combine multiple shared Jenkins libraries?
E.g. I have a common shared library: my-shared-library (git repository with a maven project) defined on a jenkins folder that contains some jobs. Each
job that runs inside that folder can use that shared library in the Jenkinsfile with:
#Library("my-shared-library") _
import com.pipelines.Pipeline
new Pipeline().build()
Now I would like to create another shared library: my-specialized-shared-library that contains a few specialized pipelines (in another git repository also as a maven project).
Pipelines (groovy classes, scripts etc) in my-specialized-shared-library should be able to use/import classes, pipelines etc from:
my-shared-library is that possible and if so what are the recommended approach?
In Manage Jenkins > Configure System I defined 2 different Global Pipeline Libraries from different URLs.
GlobalLibrary-1
GlobalLibrary-2
The .jenkinsfile:
#Library('GlobalLibrary-1#some_branch') l1 //you can write here _ (underscore) or any other string.
#Library('GlobalLibrary-2#any_branch') l2
import com.lib1.Class1; // import from GlobalLibrary-1 (Jenkins automatically finds com.lib.Class1 inside GlobalLibrary-1)
import com.prodcode.Class2; // import from GlobalLibrary-2 (Jenkins automatically finds com.prodcode.Class2 inside GlobalLibrary-2)
node {
new Class1();
new Class2();
}
I can even use imports inside Class2.groovy to get classes from GlobalLibrary-1.

F#: Why does script file not recognize module?

I create a new F# console application project in Visual Studio 2015
I create a simple new module file called Calc.fs like so:
module Calc
let add a b = a + b
I add an F# script file to the project like so:
open Calc
let c = add 1 2
I get the following compiler errors in the script file:
The namespace or module 'Calc' is not defined
and
The value or constructor 'add' is not defined
Why is my module not recognized by my script file? How can I fix this?
Please note that my script file appears after the module in the order of files in the project:
.fsx files are not compiled together with the rest of the project; they don't "know" about any other code unless you explicitly make it known to them. This is true for any external DLLs (and in fact even many in the .NET Framework) as well as other F# code.
You need to add
#load "Calc.fs"
at the top of the script file to tell the compiler to load that code before evaluating the rest of the script.

How can I overwrite parent version number in parent module from sub module

I am now building a spring application which consists of multiple spring projects as micro-services. I want to put all these spring projects into a parent module and then convert it into a multi-module maven project. But I have met a problem as each sub-module needs to have a parent reference to spring-cloud-starter-parent, so natually, I am moving this into the parent module. But now the problem happened, each submodule is using different version of spring-cloud-starter-parent. Let's see below.
part of POM for parent module:
<groupId>com.demo</groupId>
<artifactId>spring-cloud-demo</artifactId>
<version>2.0</version>
<packaging>pom</packaging>
<name>Spring Cloud Demo</name>
<parent>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-parent</artifactId>
<version>Angel.SR3</version>
</parent>
And in sub-module, part of POM is:
<parent>
<groupId>com.demo</groupId>
<artifactId>spring-cloud-demo</artifactId>
<version>2.0</version>
<relativePath>../pom.xml</relativePath>
</parent>
I though this is working, as the spring-cloud-starter-parent is already introduced in the parent module, so it will be available in the sub-module. BUT I suddenly met a problem, some child sub-module needs to have different spring-cloud-starter-parent version, for example, 1.0.0-SNAPBUILD.
In this case, how can I still use multi-module maven project structure? How can I use different parent version in the sub-module? Or I have to separate this into completely two different projects?
Thanks.
you should be able to override the parent dependency in the sub module pom to point at the specific dependencies that you need.
Dependency mediation - this determines what version of a dependency will be used when multiple versions of an artifact are encountered. Currently, Maven 2.0 only supports using the "nearest definition" which means that it will use the version of the closest dependency to your project in the tree of dependencies. You can always guarantee a version by declaring it explicitly in your project's POM. Note that if two dependency versions are at the same depth in the dependency tree, until Maven 2.0.8 it was not defined which one would win, but since Maven 2.0.9 it's the order in the declaration that counts: the first declaration wins.
"nearest definition" means that the version used will be the closest
one to your project in the tree of dependencies, eg. if dependencies
for A, B, and C are defined as A -> B -> C -> D 2.0 and A -> E -> D
1.0, then D 1.0 will be used when building A because the path from A to D through E is shorter. You could explicitly add a dependency to D
2.0 in A to force the use of D 2.0
http://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html

How do I use "rebar ct" with a two application node?

I'm using rebar to compile my application. Actually, it's two applications:
deps/
apps/A/
apps/B/
apps/B/suites
...where B depends on A. This is correctly configured in apps/B/src/B.app.src. However, when I attempt to run rebar ct, it fails to test B, reporting that it can't find A.app.
Running rebar ct in verbose mode shows that it's setting the code search path (-pa) to include apps/B/ebin, and deps/foo/ebin, deps/bar/ebin, etc.
It is not including apps/A/ebin.
How do I use Common Test to test an Erlang "application" that's made up of multiple applications?
Add in apps/B/rebar.config
{lib_dirs, [
".."
]}.
or
{ct_extra_params, "-pa ../A/ebin"}.
IMO, if B depends on A, I would have two separate tests. One for A and mention it deps section of B of rebar config and write separate test cases for B and run only for B so that application A modules would be automatically taken care by rebar.

Concern with jenkins multiple poms execution

I want to create only one job of jenkins and trigger the multiple poms with it i have done the same in ant by using the conditional buildstep plugin
My actual design is that i want to use is suppose I create the one job with name ABC and i m maintaining the tar file with this name and in this job i want to maintain the multiple builds
like ABC-type-I, ABC-type-II, ABC-type-III ........ all of them have there pom layering(maven structure) and i want to create the conditional steps like at run time i would be able to decide for which types the build is included in the tar i know that it can be done using conditional steps plugin but want to know the better approach if any in ur mind please share...........................
I find out the solution of my problem what I did is that I have used conditional build step plugin in Jenkins, so I made the one parent pom and then make the respective child pom for each sub module of my parent module and through conditional plugin I was able to give or create the prebuildsteps(go to conditional single step or multiple and then u can give the pom.xml there of your sub module) or you can make your job as dynamic as well that if you want to to include only sub module 1 not sub module 2 in your parent module than you can make the checkbox there by using the boolean parameters and executes the conditional steps only when there value is true(means checked)

Resources