セキュリティ/静的解析/Sonar/ant-sonarプラグイン追加
提供: 初心者エンジニアの簡易メモ
antインストール
- apt-get
apt-get install ant
ant環境パス追加
vi ~/.bash_profile
export ANT_HOME=/usr/bin/ant
source ~/.bash_profile
antにsonarプラグイン追加
cd /usr/local/src wget https://sonarsource.bintray.com/Distribution/sonarqube-ant-task/sonarqube-ant-task-2.5.jar
追加したいプロジェクトのbuild.xmlに追加
<?xml version="1.0" encoding="UTF-8"?> <project name="sample" default="compile" basedir="." xmlns:sonar="antlib:org.sonar.ant"> <description>Sonar1</description> <property environment="env" /> <property name="src" location="src"/> <property name="build" location="bin"/> <taskdef uri="antlib:org.sonar.ant" resource="org/sonar/ant/antlib.xml"> <classpath path="/usr/local/src/sonarqube-ant-task-2.5.jar" /> </taskdef> <target name="init"> <tstamp/> <mkdir dir="${build}"/> </target> <target name="compile" depends="init" description="compile the source"> <javac srcdir="${src}" destdir="${build}" encoding="MS932" /> </target> <target name="sonar" description="analyze project" > <sonar:sonar workDir="/tmp/sonar/sample1" key="com.example.sample1:sample1" version="0.1"> <property key="sonar.jdbc.url" value="jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8" /> <property key="sonar.jdbc.driverClassName" value="com.mysql.jdbc.Driver" /> <property key="sonar.jdbc.username" value="sonar" /> <property key="sonar.jdbc.password" value="sonar" /> <property key="sonar.host.url" value="http://localhost:8080/sonar" /> <property key="sonar.sourceEncoding" value="MS932" /> <sources> <path location="${src}" /> </sources> <property key="sonar.projectName" value="Sonar1" /> <property key="sonar.dynamicAnalysis" value="false" /> </sonar:sonar> </target> <target name="clean" description="clean up" > <delete dir="${build}"/> </target> </project>