Question

I have Code style template that defines default comments with annotations for new Java classes (see below).
How to make it insert the version from Maven pom.xml? Something like

@since ${pom.project.version}

CodeStyle_codetemplates.xml

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- 
Code Style Code Template 
To start using open Window -> Preferences
Java \ Code Style \ Code Template
Press [Import...] button and select this file.
 -->
<templates>
<template autoinsert="false" context="newtype_context" deleted="false" description="Newly created files" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.newtype" name="newtype">${filecomment}
${package_declaration}

/**
 * 
 * @since ${date}
 * @author ${user} 
 * Reviewer 
 */
${typecomment}
${type_declaration}</template></templates>
Was it helpful?

Solution

To do what you're asking, there would need to be an Eclipse plugin to provide the variables to the code template. There are some links to information on this type of plugin in the answers to Can you define your own template variables in eclipse. You could request this as a feature from the m2e project.

A faster solution would be to go in the other direction: instead of having Eclipse pull information from Maven, have Maven write the data. There are some good instructions in Using Maven to output the version number to a text file

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top