settings.localRepository
jarから外部リポジトリへのパスを解決する方法はわかりませんが、jarがローカルリポジトリにあると仮定すると、暗黙の変数を介してそれにアクセスできるはずです。次に、グループとアーティファクトIDをすでに知っているので、この場合はjarへのパスは次のようになります。settings.localRepository + "/my-group/my-artifact/1.0/my-artifact-1.0.jar"
このコードを使用すると、jarファイルを読み込んで、そこからテキストファイルを取得できます。私は通常、ファイルをbyte []に読み込むためにこのコードを書くことはないことに注意してください。完全を期すために、ここに置いています。理想的には、ApacheCommonsまたは同様のライブラリからの何かを使用してそれを行います。
def file = null
def fileInputStream = null
def jarInputStream = null
try {
//construct this with the path to your jar file.
//May want to use a different stream, depending on where it's located
fileInputStream = new FileInputStream("$settings.localRepository/my-group/my-artifact/1.0/my-artifact-1.0.jar")
jarInputStream = new JarInputStream(fileInputStream)
for (def nextEntry = jarInputStream.nextEntry; (nextEntry != null) && (file == null); nextEntry = jarInputStream.nextEntry) {
//each entry name will be the full path of the file,
//so check if it has your file's name
if (nextEntry.name.endsWith("my-file.txt")) {
file = new byte[(int) nextEntry.size]
def offset = 0
def numRead = 0
while (offset < file.length && (numRead = jarInputStream.read(file, offset, file.length - offset)) >= 0) {
offset += numRead
}
}
}
}
catch (IOException e) {
throw new RuntimeException(e)
}
finally {
jarInputStream.close()
fileInputStream.close()
}