跳轉到

GPL 的檢查

GPL 和 AGPL 不管是啥版本都要求直接引用該程式庫的專案要公開(儘管有些人反對)。

If you are not directly linking against the GPL'd library, then your software should not need to be licensed as GPL.

Reference

但是 LGPL 或 GPL with classpath exception 可以允許引用套件,但是不允許直接複製貼上進程式碼中。

There are less permissive licenses like the LGPL and the GPL with classpath exception that allow the code to be linked by any other code (so in Java terms, you can have dependencies with those licenses), but not embedded (or, more likely copy-pasted).

Reference

下表是不同許可間的比較。

image alt
image alt
來源於:The easiest way to check all your npm dependency


在多個 Repo 中找到相依套件是否有使用 GPL 的策略會是:

方法

用了哪些 script 找資料。

NPM

# data/derived/package.json.deps.txt has package name in second column, same as composer
$ awk '{print $2}' data/derived/package.json.deps.txt \
  | sort -u \
  | xargs -P 8 -I{} bash -c 'curl "https://registry.npmjs.org/{}/latest" -s \
    | jq -r '"'"'select(.name != null) | [.name, .license|tostring] | @tsv'"'"' \
    | tee -a data/derived/package.json.deps.license.txt'

Composer

$ awk '{print $2}' data/derived/composer.json.deps.txt \
  # 避免特定 vendor 的套件
  | grep -v '^104' \
  # 避免非套件的相依,例如 php
  | grep '\/' \
  | sort -u \
  | xargs -P 8 -I{} bash -c '
    curl "https://repo.packagist.org/p2/$1.json" -s \
      | jq -r ".packages[] | to_entries | .[].value | select(.name != null) | [.name, .license|tostring] | @tsv" \
      | sed "s/\",\"/\\t/g" | sed "s/\\[\"//" | sed "s/\"\\]//" \
      | tee -a data/derived/composer.json.deps.license.txt' - {}

Maven

Maven 需要的步驟有點多,先取最新版本再取該版本的 POM 檔,以下以 org.springframework.bootspring-boot-starter-data-jpa 為例。

scripts/parse-pom.js 詳見於

$ base='https://repo1.maven.org/maven2'
# 不是 `.` 做區隔而是 `/`
$ project='org/springframework/boot'
$ app='pring-boot-starter-data-jpa'
# 取得指定套件最新版本
$ curl -s "$base/$project/$app/maven-metadata.xml" \
  | grep '<latest>' \
  # 移除 <latest>2.7.1</latest> 的 tag
  | cut -c 13- | rev | cut -c 10- | rev
2.7.1

# 取該版本的 POM 檔
$ curl "$base/$project/$app/2.7.1/$app-2.7.1.pom" \
  | node scripts/parse-pom.js
org.springframework.boot pring-boot-starter-data-jpa Apache-License-Version-2.0

依照上面的邏輯,就可以使用下面的 script:

build.gradlepom.xml 差不多,只有第一步的篩選需要調一下, pom.xml 只需要篩選 dep 就可以

  • 篩選需要的資料
    1. 需要大於等於四個參數,也就是至少需要有 app 名稱
    2. path(第二個參數)需要包含 dependency 這關鍵字
    3. project 名稱(但三個參數)不能包含內部使用的
    4. project 名稱必須包含 .
    5. 把結果以 / 連結
  • 透過前面得到 metadata 的方式得到最新版本
  • 得到最新版本的 license
$ file='data/derived/build.gradle.deps'
$ filter='NF >= 4'
$ filter="$filter && \$2 ~ /.*dependency.*/"
$ filter="$filter && \$3 !~ /(104|jar|androidx|com\.cac\.)/"
$ filter="$filter && \$3 ~ /\./"
$ awk "$filter {print \$3 \"/\" \$4}" "$file.txt" | \
  sed 's/\./\//g' | \
  sort -u > "$file.trimmed.txt"

$ cat data/derived/build.gradle.deps.trimmed.txt | \
  xargs -P 8 -I{} bash -c '
    curl -s "$base/$1/maven-metadata.xml" \
    | grep "<latest>" \
    | cut -c 13- | rev | cut -c 10- | rev \
    | awk "{print \"$1 \" \$1}" >> "$file.latest.txt"' - {}

$ cat "$file.latest.txt" | \
  awk '{print $1 "/" $2 " " $1 "-" $2 ".pom"}'  | \
  sed 's/ .*\//\//g' | \
  xargs -P 8 -I{} bash -c '
    curl "$base/$1" -s \
    | node scripts/parse-pom.js \
    >> "$file.license.txt"' - {}

結果

查找結果

NPM

Composer

Maven

build.gradlepom.xml 都要跑完。