我正在尝试将使用fmpp的ant任务转换为gradle。 我无法构建我的项目。 我的构建.xml文件中有以下内容:
<project name="website">
<property file="build.properties" />
<property name="src.dir" location="src" />
<property name="build.dir" location="build" />
<taskdef name="fmpp" classname="fmpp.tools.AntTask">
<classpath>
<pathelement location="lib/fmpp.jar"/>
</classpath>
</taskdef>
<target name="clean">
<delete dir="${build.dir}" />
</target>
<target name="dist">
<fmpp sourceRoot="${src.dir}" outputRoot="${build.dir}">
<data expandProperties="yes">
base_url: ${base_url}
google_analytics_number: ${google_analytics_number}
mail_user: ${mail_user}
mail_password: ${mail_password}
mail_recipient: ${mail_recipient}
upload_folder: ${upload_folder}
host: ${host}
port: ${port}
</data>
</fmpp>
</target>
</project>
我的build.gradle文件看起来像这样
ant.taskdef(name: 'fmpp', classname:'fmpp.tools.AntTask') {
classpath {
fileset(dir: 'lib', includes: '*.jar')
}
}
ant.fmpp(sourceRoot:"src", outputRoot :"build") {
data(expandProperties: 'yes'){
base_url = base_url
google_analytics_number = google_analytics_number
mail_user = mail_user
mail_password = mail_password
mail_recipient = mail_recipient
upload_folder = upload_folder
host = host
port = port
}
}
但是当我运行它时,我收到以下错误
FMPP 处理会话失败。 原因:freemarker.core.InvalidReferenceException:表达式base_url未定义在第 15 行第 47 列 data/header.htm。
因此,似乎 htm 文件中的模板变量没有在我的构建中正确拾取和实现。 我不知道如何解决这个问题。 fmpp 有一些 gradle 插件,但文档非常有限,我很难让它们中的任何一个工作。 如果有人有建议或解决方法,将不胜感激。
***更新
以下是尝试应用的 htm 文件的示例
<head>
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
$page = basename($_SERVER['PHP_SELF']);
require_once($_SERVER['DOCUMENT_ROOT'] . '/js/functions.php');
?>
<title>
<#if title??> ${title}
<#else> CompSci Resources, LLC | The Complete EDGAR and XBRL Filing Platform, and more!
</#if>
</title>
<script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js'></script>
<script type='text/javascript' src='${base_url}/js/bootstrap-filestyle.min.js'> </script>
<script type='text/javascript' src='${base_url}/js/bootstrap.min.js'></script>
<script type='text/javascript' src='https://cdnjs.cloudflare.com/ajax/libs/jcarousel/0.3.4/jquery.jcarousel.js'></script>
<script type='text/javascript' src='https://cdnjs.cloudflare.com/ajax/libs/jcarousel/0.3.4/jquery.jcarousel-autoscroll.min.js'></script>
<script type='text/javascript' src='${base_url}/js/compsci.js'></script>
<script type='text/javascript' src='${base_url}/js/carousel.js'></script>
<script type='text/javascript' src='${base_url}/js/readmore.js'></script>
<link rel='shortcut icon' href='${base_url}/images/littlelogo.png' >
<link rel='stylesheet' type='text/css' href='${base_url}/css/jcarousel.css' >
<link rel='stylesheet' type='text/css' href='${base_url}/css/bootstrap.css'>
<link rel='stylesheet' type='text/css' media='screen, projection' href='${base_url}/css/compsci.css'>
<style type='text/css'>
@media screen and (-webkit-min-device-pixel-ratio:0) {
h2 { font-weight: normal; }
.csr-services-popper-left { margin-top:11px; }
}
</style>
<!-- Google Analytics -->
<script type='text/javascript'>
//Google Analytics
var _gaq = _gaq || [];
_gaq.push(['_setAccount', '${google_analytics_number}']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<meta charset="UTF-8">
<meta name="language" content="en">
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
问题在于从gradle.properties
读取的属性和数据属性的名称完全相同。要修复它,您需要使用project
实例引用隐藏在属性下的值,例如:
base_url = project.base_url
看看我刚刚准备的演示。它运行没有任何错误。如果在gradle.properties
中重命名属性,则可以跳过project
,这是port2
属性的情况 - 故意重命名。