step1:检查项目中有没有引入jira-api包,如果没有则在pom文件中引入:
<dependency>
<groupId>com.atlassian.jira</groupId>
<artifactId>jira-api</artifactId>
<version>${jira.version}</version>
<scope>provided</scope>
</dependency>
step2:创建包目录,建立新的java文件JiraCustomField.java
@Scanned
public class JiraCustomField extends GenericTextCFType{
protected JiraCustomField(
@JiraImport CustomFieldValuePersister customFieldValuePersister,
@JiraImport GenericConfigManager genericConfigManager,
@JiraImport TextFieldCharacterLengthValidator textFieldCharacterLengthValidator,
@JiraImport JiraAuthenticationContext jiraAuthenticationContext){
super(customFieldValuePersister, genericConfigManager, textFieldCharacterLengthValidator, jiraAuthenticationContext);
// TODO Auto-generated constructor stub
}
}
step3:创建前端vm文件edit.vm
#controlHeader ($action $customField.id $customField.name $fieldLayoutItem.required $displayParameters.noHeader)
#if ($jiraUserUtils.getGroupNamesForUser($authcontext.loggedInUser.name).contains(\'jira-administrators\'))
<input type="text"
name="$customField.id"
value="$!value" />
#else
#if($value && ! $value.equals(""))
#set ($displayValue = ${value})
#else
#set ($displayValue = \'N/A\')
#end
<span title="This field is editable only by JIRA administrators">$!displayValue</span>
<input type="hidden"
name="$customField.id"
value="$!value" />
#end
#controlFooter ($action $fieldLayoutItem.fieldDescription $displayParameters.noHeader)
step4:编辑atlassian-plugin.xml:
<customfield-type name="Jira Custom Field" i18n-name-key="jira-custom-field.name" key="admintextfield" class="com.atlassian.plugins.tutorial.customfield.JiraCustomField">
<description>A text field only editable by those with admin permissions</description>
<resource name="edit" type="velocity" location="template/edit.vm"/>
</customfield-type>
step5:properties文件中新增:jira-custom-field.name=\u6D4B\u8BD5\u65B0\u589E\u81EA\u5B9A\u4E49\u5B57\u6BB5\u7C7B\u578B(支持国际化,手动翻译)
最后,打包上传看到效果如下: