Download/import all dependencies from Spring IO - spring

I work for a large organization where all development tools must go through a rigorous certification process and security assessment. I want to have Spring IO Brussels SR2 certified, along with Apache Maven.
I'd like to provide them with a ZIP file containing all JARs (dependencies and transitive dependencies) of the Spring IO platform so they can do the security assessment on it.
Being a new Maven user, I've created a new Maven project in Eclipse, and simple added this in pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>my.company</groupId>
<artifactId>MySpringApp</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>MySpringApp Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>io.spring.platform</groupId>
<artifactId>platform-bom</artifactId>
<version>Brussels-SR2</version>
<type>pom</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>MySpringApp</finalName>
</build>
</project>
The project compiles and packages correctly, but it's not importing/adding any JARs to the packaged WAR file. I've also tried to change the scope to compile.
Is it possible? Is it because it's a bill of material?
Thank you

According to the Website you have to enable the dependency-tree using
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>my.company</groupId>
<artifactId>MySpringApp</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>MySpringApp Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.spring.platform</groupId>
<artifactId>platform-bom</artifactId>
<version>Brussels-SR2</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</dependency>
<build>
<finalName>MySpringApp</finalName>
</build>
</project>
Eclipse and Maven are designed to be able to work alone, a bit of experiences is required to let them work together, often a cleanup using Update Project ... (project-rightclick/maven) is required

I ended up downloading the dependency versions list into a CSV file, then loop through it in a simple Java class, outputting the results in a tag manually. Then, I was able to copy/paste all those tags into my pom.xml file and then get all those dependencies resolved by Maven.
Finally, I have taken the content of /target/WEB-INF/lib.

Related

Not able to access maven dependency from a common folder in same directory

I am using a multi-module approach in Spring boot application. My directory structure is like
package name
|_bom
|__common-test
|__service
|_src/test/java/TestFile.java
I have put test related dependencies in pom.xml of common-test and accessing them in test folder of service. I am able to access most of the dependencies in TestFile.java but not the dependency mentioned below. This is the last dependency in pom.xml of common-test. Following the same structure I am able to use mockito dependency but not this one.
I have defined related properties in bom/pom.xml which are to be used in common-test/pom.xml. Using this approach for first time and not sure how to achieve this. Basically, I need to maintain test related dependencies in common-test pom.xml and not include it in service.
import org.junit.jupiter.migrationsupport.rules.EnableRuleMigrationSupport;
pom.xml of common-test have this dependency
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>projeectname</artifactId>
<groupId>in.packagename.mint</groupId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>projeectname-common-test</artifactId>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>in.packagename.mint</groupId>
<artifactId>projeectname-bom</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<!-- project dependencies -->
<dependencies>
<!-- https://mvnrepository.com/artifact/org.mockito/mockito-junit-jupiter -->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-migrationsupport</artifactId>
</dependency>
</dependencies>
</project>
pom.xml of bom
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<!-- parent coordinates -->
<parent>
<groupId>in.packagename.mint</groupId>
<artifactId>projectname</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<artifactId>projectname-bom</artifactId>
<properties>
<junit.jupiter.migration-support.version>5.7.0</junit.jupiter.migration-support.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>3.5.13</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-migrationsupport</artifactId>
<version>${junit.jupiter.migration-support.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>
</project>
I have tried deleting .m2 folder and building all these bom, common-test, etc. separately and runnning mvn install but this dependency issue is not resolved and not able to import it in service test folders.

How to use controller service api from a dependency

I have a custom controller service that I want to use together with the ConnectWebSocket processor. The controller service depends on nifi-websocket-services-api and does not need a custom api (the my-customer-controller-service-api folder is empty). I have written a test for the controller service and it is passing.
However I cannot select the controller service, because ConnectWebSocket only accepts a controller service api from nifi-websocket-service-api-nar.
I want to avoid to recode the entire ConnectWebSocket processor. So my question is:
Is it possible to configure the dependencies such that my custom controller service uses the api that comes from nifi-websocket-service-api-nar?
pom.xml of controller-service:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.mydomain</groupId>
<artifactId>nifi-controllerservice-bundle</artifactId>
<version>1.9.2</version>
</parent>
<artifactId>nifi-controllerservice</artifactId>
<packaging>jar</packaging>
<dependencies>
<!-- normal dependencies -->
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-processor-utils</artifactId>
<version>1.9.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-websocket-services-api</artifactId>
<version>1.9.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-websocket-services-jetty</artifactId>
<version>1.9.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-ssl-context-service-api</artifactId>
<scope>provided</scope>
</dependency>
<!-- Test dependencies -->
</dependencies>
pom.xml of controller-service-nar
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.mydomain</groupId>
<artifactId>nifi-controllerservice-bundle</artifactId>
<version>1.9.2</version>
</parent>
<artifactId>nifi-controllerservice-nar</artifactId>
<version>1.9.2</version>
<packaging>nar</packaging>
<properties>
<maven.javadoc.skip>true</maven.javadoc.skip>
<source.skip>true</source.skip>
</properties>
<dependencies>
<dependency>
<groupId>com.mydomain</groupId>
<artifactId>nifi-controllerservice</artifactId>
<version>1.9.2</version>
</dependency>
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-websocket-services-jetty</artifactId>
<version>1.9.2</version>
<scope>nar</scope>
</dependency>
</dependencies>
</project>
root pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-nar-bundles</artifactId>
<version>1.9.2</version>
</parent>
<groupId>com.mydomain</groupId>
<artifactId>nifi-controllerservice-bundle</artifactId>
<version>1.9.2</version>
<packaging>pom</packaging>
<modules>
<module>nifi-comtom</module>
<module>nifi-comtom-nar</module>
</modules>
</project>
This should be the standard way processors and controller services work...
Processors depend on an interface which comes from the service API NAR, and controller service implementations implement that interface. The framework then knows all the implementations of that interface which allows is to provide the possible services that can be used.
Without seeing your project and poms it is hard to say what the problem is, but most likely it is a dependency issue. Your project structure should have two Maven modules, one that produces a jar for your service impl, lets call this one custom-service, and then one that packages the NAR, lets call this custom-service-nar.
The custom-service module should have a provided dependency on nifi-websocket-services-api, this allows it to compile, but we don't want to bundle that API since at runtime it will come from another NAR.
The custom-service-nar module should have a dependency of type NAR on the nifi-websocket-services-api-nar.
https://cwiki.apache.org/confluence/display/NIFI/Maven+Projects+for+Extensions#MavenProjectsforExtensions-LinkingProcessorsandControllerServices

Problems when compiling and running a simple Maven project with Spring in JDeveloper 12c

I'm trying to compile and run the first examples of the book "Beginning Spring" in JDeveloper but I'm running with some issues.
Here's the pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.wiley.beginningspring</groupId>
<artifactId>spring-book-ch2</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>spring-book-ch2</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.0.5.RELEASE</version>
</dependency>
</dependencies>
<repositories/>
<pluginRepositories/>
</project>
JDeveloper marks the following imports with errors of package not found:
import org.springframework.beans.factory.annotation.Autowire;
import org.springframework.beans.factory.annotation.Qualifier;
Of course I can't compile the project since those errors are present.
I've already installed Spring integration in the Updates menu.
In Netbeans 8 and Spring Tool Suite the project marks no errors and compiles and runs fine.
Try adding this dependency to your pom.xml
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>4.1.6.RELEASE</version>
</dependency>

What is the difference between tags parent, dependency and plugin (Maven)

I am confused by the fact that POM.xml contains parent, dependency and plugin. Somethings something specified with parent must be again included in dependency, for example
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>my-app</name>
<url>http://maven.apache.org</url>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.2.3.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.1.6.RELEASE</version>
</dependency>
</dependencies>
</project>
Why do I have to specify a dependency twice ? How can I use these three tags ?
The parent is a POM which gets "inherited", it basically gets combined with your current POM by means of overwriting. (You can use "mvn help:effective-pom" to print the combined result). So all the dependencies and plugins in the parent will become yours (and all managed dependency versions, which is in case of spring-boot a majority).
The dependendency specifies artifacts you need on your classpath for compiling or testing or running your project (depending on its scope).
Whereas plugin is a artifact which gets executed at build time (like a compiler, report generator and stuff).
I would suggest to read a good tutorial or book on maven, my simple explanation is not enough to make good use of it. https://maven.apache.org/articles.html

Accessing Elasticsearch through JAVA API with Eclipse

I'm a beginner trying to access elasticsearch through JAVA with eclipse, but after following the instructions available at this guide , eclipse is not able to import packages like org.elasticsearch.node.* and I haven't been able to continue.
This is my first time with Maven, and the configurations might be wrong.
This is my pom.xml file:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>elasticsearch</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>${es.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
I can access elasticsearch through a terminal or browser, but not with eclipse. What step I am missing?
You haven't defined es.version in your properties section. mvn install should have thrown errors because it can't download elasticsearch dependencies. I think following change to your pom would work.
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<es.version>0.90.3</es.version>
</properties>
Here is the pom.xml in my eclipse Maven project. It works. Just for you reference.
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>elastic.mapper</groupId>
<artifactId>importer</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>importer</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>2.0.0</version>
</dependency>
</dependencies>
</project>

Resources