1

I am pretty new with Apache Nifi and NARs in general. I am creating a custom processor NAR project which needs to reference classes from the jars present in another NAR file. I don't have access to the project(source code) which has generated this NAR. So I am trying to include this NAR file as a maven dependency. This is similar to how you would add an external/local jar as a maven dependency. What would be the right way to achieve this?

NOTE: My custom project is a child project of "nifi-nar-bundles" so it will inherit the "nar-maven-plugin"

<parent>
    <groupId>org.apache.nifi</groupId>
    <artifactId>nifi-nar-bundles</artifactId>
    <version>1.11.4</version>
</parent>

I am using eclipse with its maven plugin and have tried few things:

#1

<dependency>
    <groupId>com.group.test</groupId>
    <artifactId>test-nar</artifactId>
    <version>1.0.0</version>
    <scope>system</scope>
    <type>nar</type>
    <systemPath>C:\test-nar-1.0.0.nar</systemPath>
</dependency>

This does not add the NAR file under "Maven Dependencies" in eclipse. However if I remove <type>nar</type> it shows the NAR file under "Maven Dependencies" but does not put its jars in the classpath.

#2

I installed the NAR in my local maven repository with packaging as "nar" using below command:

mvn install:install-file -Dfile=test-nar-1.0.0.nar -DgroupId=com.group.test -DartifactId=test-nar -Dversion=1.0.0 -Dpackaging=nar

and then put it as a dependency in the pom.xml file as below:

<dependency>
    <groupId>com.group.test</groupId>
    <artifactId>test-nar</artifactId>
    <version>1.0.0</version>
    <type>nar</type>
</dependency>

This does not add the NAR file under "Maven Dependencies" in eclipse either.

user1144004
  • 183
  • 3
  • 4
  • 21

1 Answers1

0

The test-nar dependency of type "nar" should be included in your NAR module, and if you can't bring in its dependencies to your code module (not your NAR module) as provided you might need to include the NAR itself as provided in your code module, in order to get the code module to compile. However the dependencies will be provided by the parent NAR (test-nar) at runtime.

mattyb
  • 11,693
  • 15
  • 20
  • "you might need to include the NAR itself as provided in your code module" -> How do I include it as provided in the code module. Isn't that what I am doing in the config I posted? If not, can you elaborate with a sample? However I do need to reference the classes from the dependencies at compile time in my custom project for writing testcases. – user1144004 Jun 18 '21 at 11:23
  • In NiFi you'll see examples of how modules are set up, usually there's a top-level bundle that has the NAR module and a code module (see nifi-scripting-nar and nifi-scripting-processors under the nifi-scripting bundle as an example). In those cases the NAR lists nifi-scripting-processors (the code/JAR) as a dependency so it gets into that NAR. What you're trying to do is have your NAR use another NAR as a parent, which is correct the way you have it above. But you likely need to bring in something like "nifi-scripting-processors" (in this example) as a provided JAR in your code module's POM – mattyb Jun 22 '21 at 15:04