You can make use of Special Library path to make your application use your custom library for Yarn application master. To do this, run the below command in Spark shell after running your Spark application.
val sc = new SparkContext(new SparkConf())
./bin/spark-submit <all your existing options> --spark.yarn.am.extraLibraryPath= <path to custom library>