将 FMPP 与 Gradle 一起使用

Using FMPP with Gradle

我正在尝试将使用 fmpp 的 ant 任务转换为 gradle。我无法构建我的项目。我的 build.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 processing session failed. Caused by: freemarker.core.InvalidReferenceException: Expression base_url is undefined on line 15, column 47 in 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

看看我刚刚准备的demo。它运行没有任何错误。如果您重命名 gradle.properties 中的属性,您可以跳过 projectport2 就是这种情况 属性 - 故意重命名。