I want to share solution for gradle based project. 
This solution allows to get any build's properties on client/server.

*1) Add to build.gradle*
...
task createProperties(dependsOn: processResources) {
doLast {
 new 
File("$buildDir/resources/main/yourmodule/shared/IVersion.properties").withWriter
 
{ w ->
  Properties p = new Properties()
  p['version'] = project.version.toString()
  p.store w, null
 }
}
}

classes {
  dependsOn createProperties
}
...
*2) Add IVersion.java:*

package yourmodule.shared;
import com.google.gwt.i18n.client.Constants;
public interface IVersion extends Constants {
   String version();
}

*3) Add to your code*
*...*
public static final IVersion versionResource = GWT.create(IVersion.class);
...
*4) Get version value on client side:*
*...*
versionResource.version();
...
*5) Get version on server side:*
*...*
InputStream stream = this.getClass().getResourceAsStream(
"/yourmodule/shared/IVersion.properties");
InputStreamReader readerIs;
try {
  readerIs = new InputStreamReader(stream, "UTF-8");
  messageInstance = new PropertyResourceBundle(readerIs);
  messageInstance.getString("version"); 
} catch (Exception e) {
  e.printStackTrace();
}
*...*

вторник, 13 марта 2018 г. в 13:12:30 UTC+4, Bruno Salmon: 

> Thanks Thomas, I'm using GWT 2.8.2 so I tried your first suggestion and it 
> works :-)
>
> I just declared the property in my gwt.xml module file:
>
> <define-configuration-property name="build.number" is_multi_valued="false"/>
>
>
>  and set its value (with the maven property which is set by Jenkins) when 
> calling your plugin in the configuation section: 
>
> <configuration>
>     <compilerArgs>
>         <compilerArg>-setProperty</compilerArg>
>         <compilerArg>build.number=${build.number}</compilerArg>
>     </compilerArgs>
> </configuration>
>
>
> Then System.getProperty("build.number") returns the expected value :-)
>
> Thank you
>
> On Monday, 12 March 2018 23:27:17 UTC+1, Thomas Broyer wrote:
>>
>> Easiest with recent GWT version would be to declare a 
>> <configuration-property>, get it using System.getProperty(), and set it 
>> with --property.
>>
>> With older versions, use Maven filtering on a properties file you use 
>> with a com.google.gwt.i18n.client.Constants; or have a look at Mojo's Java 
>> template plugin.
>>
>

-- 
You received this message because you are subscribed to the Google Groups "GWT 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-web-toolkit/aa760b0f-d641-4741-bb50-d58fb5585499n%40googlegroups.com.

Reply via email to