Some projects have added a "no military use" clause to the GPL [1] to do this.
https://www.linux.com/news/open-source-project-adds-no-milit...
https://www.linux.com/news/open-source-project-adds-no-milit...
EDIT: oops, they actually asked him later in the article.