Check resolve for YangLibrary before constructing new one

Change-Id: I7c9e92c22e6d3fe0d782336394a23db1fd19884f
diff --git a/compiler/plugin/buck/src/main/java/org/onosproject/yang/compiler/plugin/buck/YangLibraryDescription.java b/compiler/plugin/buck/src/main/java/org/onosproject/yang/compiler/plugin/buck/YangLibraryDescription.java
index 3388820..1a65719 100644
--- a/compiler/plugin/buck/src/main/java/org/onosproject/yang/compiler/plugin/buck/YangLibraryDescription.java
+++ b/compiler/plugin/buck/src/main/java/org/onosproject/yang/compiler/plugin/buck/YangLibraryDescription.java
@@ -97,7 +97,9 @@
         BuildRuleParams yangParams = params.copyWithBuildTarget(
                 BuildTargets.createFlavoredBuildTarget(
                         unflavoredBuildTarget, SOURCES));
-        BuildRule yangLib = resolver.addToIndex(new YangLibrary(yangParams, pathResolver, args.srcs));
+
+        BuildRule yangLib = resolver.getRuleOptional(yangParams.getBuildTarget())
+                .or(resolver.addToIndex(new YangLibrary(yangParams, pathResolver, args.srcs)));
 
         if (params.getBuildTarget().getFlavors().contains(SOURCES)) {
             return yangLib;